如何踢掉从不同shell登录的其他root用户?

Raj*_*pui 2 terminal shell kill

我登录到一台机器,然后输入:

insite1@POC-Messaging1:/opt/insiteone/log> last -a | grep "logged"
insite1  pts/6        Tue Jul 30 03:59   still logged in    160.110.5.210
root     pts/5        Tue Jul 30 02:28   still logged in    160.110.154.231
root     pts/4        Tue Jul 30 02:26   still logged in    160.110.154.231
root     pts/0        Tue Jul 30 02:18   still logged in    160.110.5.210
root     pts/3        Tue Jul 30 02:13   still logged in    160.110.5.210
root     pts/2        Tue Jul 30 01:00   still logged in    160.110.154.231
root     pts/1        Tue Jul 30 00:47   still logged in    160.110.154.231
Run Code Online (Sandbox Code Playgroud)

我想杀死除了从 160.110.5.210 登录的用户之外的其他人。怎么做?

use*_*686 5

终止终端登录会话的最简洁方法是向所有进程 \xe2\x80\x93 发送 SIGHUP “挂起”信号,该信号也会在关闭终端窗口或 SSH 连接时发送。

\n\n
pkill -HUP -t pts/1\n
Run Code Online (Sandbox Code Playgroud)\n\n

使用pgreporpkill比 更容易ps|grep|grep|grep|grep|grep|grep

\n\n

如果你想编写这样的脚本:

\n\n
for tty in $(who | awk \'$1 == "root" {print $2}\'); do\n    test $tty = ${thistty=$(tty)} || pkill -HUP -t $tty\ndone\n
Run Code Online (Sandbox Code Playgroud)\n

  • ...如果您为 root 执行此操作,这可能是一个非常非常糟糕的主意... (3认同)