Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I've been having this issue, that when I exit a ssh session, it never quits properly. I have to kill it with Ctrl-C.

Example Session Below:

[stefan@desktop ~]$ ssh stefan@10.0.0.4
[stefan@laptop ~]$ # do some stuff
[stefan@laptop ~]$ exit
logout
^CKilled by signal 2.
[stefan@desktop ~]$

Is there a reason this happens? ( some running proccess that blocks a clean exit perhaps ). And how can I fix it?

share|improve this question
    
What happens if you use logout directly or issue a Ctrl+D? –  N J Nov 12 '10 at 22:52
    
Note that if you use X-forwarding and you exit some program it could be that a socket is left it CLOSE_WAIT state. During this time the connection is still not completely terminated. The length of CLOSE_WAIT is configurable. (a socket goes into CLOSE_WAIT state to wait for possible stray TCP packets arriving late). –  kasterma Nov 13 '10 at 0:10
add comment

1 Answer 1

up vote 3 down vote accepted

From the ssh man page:

The session terminates when the command or shell on the remote machine exits and all X11 and TCP connections have been closed.

You've killed your shell, but it looks like some application still has a connection open over a forwarded port (the agent, X11, or a forwarding set up with -D, -L, -R or their ~/.ssh/config equivalent).

If you don't know what program is using the forwarding, use lsof -p $pid where $pid is the process id of the ssh client (on the client) or the sshd process that was the parent of the shell (on the server) to find out what ports it has open connections on. Then use lsof -i -n or netstat -pnt and search for processes that have connections open on these ports.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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