Search code examples
sshterminatekill-process

How to terminate an ssh session that is connected to my computer


My friend turned on remote login and I disabled it, but since he was already logged in, it didn't terminate the session(I knew he did it and we we're having a race).

He created a user account and I deleted the user account which terminated the session. In the future how can I terminate the ssh session?

I was trying to use these to no avail

w
~
ssh
ps -C ssh
ps. grep ssh
ps | grep ssh
pkill 1020
kill -9 1020
netstat -lnpt | awk '$4 ~ /:1234$/ {sub(/\/.*/, "", $7); print $7}'
sudo pkill loginwindow

Solution

  • Figured it out.

    w //for established connections, get user name
    ps -u <username> //for process id process name is sshd, get process id
    sudo kill <process id>
    enter password