I am able to see logged-in users via the who
or last
command.
How can I log off a particular user who login through SSH?
I am able to see logged-in users via the who
or last
command.
How can I log off a particular user who login through SSH?
kill its ssh session. Check them by
ps aux | egrep "sshd: [a-zA-Z]+@"
Second column gives you the PID. Then,
sudo kill [-9] PID
Hope this helps.
ps: using the -9 flag will prevent things from stopping "graciously".
I found this guys. Just replace USERNAME with the desired user session to be killed.
kill [-9] $(ps aux | grep USERNAME@ | head -n 1 | tr -s ' ' | cut -f 2 -d ' ')
As mentioned above, using the -9 flag will prevent things from stopping "graciously".
ps ax
does not show the username
– false
May 13 '14 at 12:55
USERNAME@
is too loose and it might appear legitimately in other programs CLIs. But besides, I recommend that you never pipe or apply ps | grep
output to kill without inspecting it first.
– PEdroArthur
Feb 24 '21 at 02:15