Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have ControlPersist 4h in my .ssh/config and it works perfectly,
Every now and then I need to connect to this server that requires some special authentication, and if I don't use that account for while it locks my account,

the problem happens like this, I don't use my account for a while, then I ssh into the server, it checks and my account is locked so it says so but it does not actually kick me out, so if I go away (Ctrl-D, or closing the terminal) and contact the admin to unlock my account and try to connect again, my session is "kept alive" on my end and it basically does not try again, unless I reboot, or kill all ssh related processes, which is annoying,

Is there a way to close these sessions which are living in the background?

share|improve this question
Do you mean you want to exchange running kill <process> with running <close_command> <process>? Aren't you still just running a command? I don't understand what the difference is. – bahamat Oct 4 '12 at 18:35
I don't want to kill the ssh process, as I usually have multiple ssh connections at the same time, and I am not sure even killing the ssh process closes the sessions that are kept alive with the ControlPersist thing, there should be a way to ask ssh to close these. – Ali Oct 5 '12 at 12:33

You want the -O exit option to ssh.

krall@localhost $ ssh -o ControlPersist=yes otherbox
krall@otherbox $ exit
Shared connection to otherbox closed
krall@localhost $ ssh otherbox -O exit

Another option is -O stop, which makes the control master stop accepting connections, or close if nothing is currently connected.

share|improve this answer

If you ps -ef | grep {hostname} of the connection, you can then kill -9 the process and it will reset the connection.

share|improve this answer
so basically you are saying ControlPersist works only by keeping the ssh processes running in the background? – Ali Nov 29 '12 at 16:41

Your Answer


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.