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