How TO Kill and Logout users in pts/* Linux
Sometimes you may need to force logout and kill a specific user, or an active user in pts/0 pts/1 pts/3 etc.
First of all display the out put of “w” command.
[oracle@ggsdb ~]$ w
11:12:55 up 95 days, 20:13, 3 users, load average: 3.13, 3.36, 4.46
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 192.168.212.217 10:49 22:01 3.44s 3.44s top
oracle pts/5 192.168.212.221 10:55 1.00s 0.02s 0.00s w
root pts/4 192.168.212.217 10:50 15:35 0.01s 0.01s -bash
Here the user “root” is logged in from two terminal ip 192.168.212.217. and statue was IDLE. And you need to force logout and kill the user “root” logged in from ip: 192.168.212.221 (pts/5)
use the below command
[root@ggsdb ~]# skill -KILL -v pts/4
pts/4 root 29267 bash
[root@ggsdb ~]# w
11:19:46 up 95 days, 20:20, 2 users, load average: 2.45, 3.89, 4.42
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/1 192.168.212.217 10:49 20.00s 0.00s 0.00s -bash
oracle pts/5 192.168.212.221 10:55 0.00s 0.04s 0.00s sshd: oracle [priv]
This command will force logout and kill the user in pts/4. and the same user logged in pts/1 will not be logged out.
If need to kill a users all the connected sessions at once
[root~#]skill -KILL -u root (this will kill both pts/4 and pts/5 sessions)
To STOP/PAUSE a user’s activities
[root~#]skill -STOP -u <username>
To RESUME a stopped user
[root~#]skill -CONT -u <username>
The ultimate command to kill and logout all users is as follows:
# skill -KILL -v /dev/pts/*
WARNING! These tools are obsolete, unportable and it is here due to historical reasons. Consider using the killall, pkill, and pgrep commands instead as follows.
pkill command
To halt or stop a user called bob, enter:
# pkill -STOP -u bob
To resume a user called bob, enter:
# pkill -CONT -u bob
[root@ggsdb ~]# w
11:37:43 up 95 days, 20:38, 3 users, load average: 0.07, 0.27, 1.48
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/2 192.168.212.217 11:20 17:07 0.00s 0.00s -bash
root pts/1 192.168.212.217 11:20 17:10 0.00s 0.00s -bash
oracle pts/5 192.168.212.221 10:55 0.00s 0.05s 0.00s sshd: oracle [priv]
[root@ggsdb ~]# pkill -kill -t pts/1
[root@ggsdb ~]# w
11:38:21 up 95 days, 20:38, 2 users, load average: 0.03, 0.24, 1.41
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/2 192.168.212.217 11:20 17:45 0.00s 0.00s -bash
oracle pts/5 192.168.212.221 10:55 0.00s 0.05s 0.00s sshd: oracle [priv]
In Linux, PTS stands for Pseudo Terminal Slave. PTS refers to a user currently logged in to your terminal using an SSH or telnet connection. Killing a PTS will send a kill command to that user’s connection, closing it. Both active and idle users can be logged out using this command. Killing a user’s connection will not prevent him from logging in again in the future.
对不起,这篇文章暂时关闭评论。