Linux kicks out other users logging in via SSH

Source: Internet
Author: User
Tags pkill
In some production platforms or security audits, we often see a lot of users connect to the same server by using SSH, or the processes that are not properly closed after the connection still reside in the system. It is also necessary to limit the number of SSH connections and manually disconnect idle connections. here, we will write a process to manually remove other users. In some production platforms or security audits, we often see a lot of users connect to the same server by using SSH, or the processes that are not properly closed after the connection still reside in the system. It is also necessary to limit the number of SSH connections and manually disconnect idle connections. here, we will write a process to manually remove other users.

1. View online users of the system

[Root @ testdb ~] # W

14:30:26 up 38 days, 3 users, load average: 0.00, 0.01, 0.05
User tty from login @ IDLE JCPU PCPU WHAT
Root pts/0 162.16.16.155 0.00 s 0.07 s 0.05 s w
Root pts/1 162.16.16.155 12.00 s 0.01 s 0.01 s-bash

Root tty1: 0 05Dec13 38 days/usr/bin/Xorg: 0-nr-verbose-audit 4-auth/var/run/TPD/auth-for-gdm-LrK8wg/database-noliste

2. check which terminal belongs to you at this time (I have opened two connections)

[Root @ testdb ~] # Who am I

Root pts/0 (162.16.16.155)

3. pkill a terminal that is not applicable to you

[Root @ testdb ~] # Pkill-kill-t pts/1

4. view the current terminal information

[Root @ testdb ~] # W
14:31:04 up 38 days, 2 users, load average: 0.00, 0.01, 0.05
User tty from login @ IDLE JCPU PCPU WHAT
Root pts/0 162.16.16.155 0.00 s 0.04 s 0.01 s w
Root tty1: 0 05Dec13 38 days/usr/bin/Xorg: 0-nr-verbose-audit 4-auth/var/run/TPD/auth-for-gdm-LrK8wg/database-noliste
[Root @ testdb ~] #

Note:

If the task is still not killed, we recommend that you add-9 to force the task to be killed.

[Root @ testdb ~] # Pkill-9-t pts/1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.