I sshed into a Linux machine (bash shell) from a public Windows machine (in our lab) and forgot to log out. I'm now back at my seat in another room and I am too lazy to walk back and log out that session; I can ssh into the Linux machine from my current PC though. Can I force-logout the other session from a new SSH session?

When I ssh to the Linux box from my current PC and type users command, I can see that I'm still logged in there; my name is listed twice - one for the current session and another for the session from lab PC.

I don't have root privileges on the said machine, but I guess that shouldn't matter as I'm just trying to log out myself.

link|improve this question
feedback

1 Answer

up vote 6 down vote accepted

Run tty on your current session, to find out on which tty you are working, so you do not log yourself out from current session. Run w to show you current users and associated pseudo-terminals(tty). Assuming that you are logged twice and there are no other users on your ssh server, your previous ssh session will be on pts/0 and current on pts/1. To ditch the session on pts/0 simply kill processes that are associated to it with

pkill -9 -t pts/0 
link|improve this answer
For some reason, pkill -9 pts/tty-number didn't work for me; then I found the pid of the process using ps aux | grep amar and tried pkill -9 -P pid and it worked. Thanks! – Amarghosh Sep 27 '10 at 5:24
1  
pkill -9 -t pts/tty-number. -t is the switch to specify tty – Casual Coder Sep 27 '10 at 5:35
Ooops, somehow I missed that -t in your answer when I read it first. – Amarghosh Sep 27 '10 at 6:37
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.