You may also encounter this situation. in management or other cases, you need to force disable some users' sessions. Generally, you may be familiar with finding all the processes in the user session and kill them. This method works in most cases. However, if the user session unexpectedly exits... Info & n
You may also encounter this situation. in management or other cases, you need to force disable some users' sessions. Generally, you may be familiar with finding all the processes in the user session and kill them. This method works in most cases. However, when a user's session unexpectedly exits, it will be difficult to achieve the effect.
This article describes two methods to delete a session of a specified user. It can be completed without knowing the user process number, improving work efficiency.
Run the tty command to view the session number of the current session. Don't kill yourself. it's something the Japanese love to do, not what the Chinese people do:
[Root @ localhost ~] # Tty
/Dev/pts/2
[Root @ localhost ~] #
Run the w command to check which sessions are currently logged on to the server.
[Root @ localhost ~] # W
21:42:34 up, 5 users, load average: 0.44, 0.55, 0.70
User tty from login @ IDLE JCPU PCPU WHAT
Root: 0-19: 15? Xdm? 36: 42 0.09 s/bin/sh/usr/bin/startkde
Root pts/1: 0 2: 26 m 0.00 s 3.09 s kded -- new-startup
Root pts/2: 0 0.00 s 0.07 s 0.02 s w
Root pts/4: 0 0.16 s 0.01 s man pkill
Root pts/6: 0 0.11 s 0.02 s man killall
[Root @ localhost ~] #
Use the following two commands to delete a specified session. For example, to delete a session of pts/4:
[Root @ localhost ~] # Skill-KILL-v pts/4
Pts/4 root 24670 bash
[Root @ localhost ~] # W
21:45:43 up, 4 users, load average: 0.35, 0.52, 0.66
User tty from login @ IDLE JCPU PCPU WHAT
Root: 0-19: 15? Xdm? 36: 59 0.09 s/bin/sh/usr/bin/startkde
Root pts/1: 0 2: 29 m 0.00 s 3.23 s kded -- new-startup
Root pts/2: 0 0.00 s 0.06 s 0.01 s w
Root pts/6: 0 0.11 s 0.02 s man killall
[Root @ localhost ~] #
Compared with the preceding w command, we found that pts/4 is missing, proving that the session of pts/4 has been killed.
The skill command is old. We recommend that you use the new command pkill in the man manual:
This time we kill the pts/3 session:
[Root @ localhost ~] # W
21:50:34 up, 5 users, load average: 0.53, 0.53, 0.62
User tty from login @ IDLE JCPU PCPU WHAT
Root: 0-19: 15? Xdm? 37: 21 0.09 s/bin/sh/usr/bin/startkde
Root pts/1: 0 2: 34 m 0.00 s 3.35 s kded -- new-startup
Root pts/2: 0 0.00 s 0.06 s 0.01 s w
Root pts/6: 0 0.11 s 0.02 s man killall
Root pts/3: 0 0.04 s 0.03 s/bin/bash
[Root @ localhost ~] # Pkill-9-t pts/3
[Root @ localhost ~] # W
21:50:58 up, 4 users, load average: 0.54, 0.53, 0.62
User tty from login @ IDLE JCPU PCPU WHAT
Root: 0-19: 15? Xdm? 37: 23 0.09 s/bin/sh/usr/bin/startkde
Root pts/1: 0 2: 35 m 0.00 s 3.35 s kded -- new-startup
Root pts/2: 0 0.00 s 0.07 s 0.01 s w
Root pts/6: 0 0.11 s 0.02 s man killall