10

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?

2
  • 1
    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. Commented Oct 4, 2012 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. Commented Oct 5, 2012 at 12:33

2 Answers 2

11

You want the -O exit option to ssh.

krall@localhost $ ssh -o ControlPersist=yes otherbox Password: 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.

1
  • So I cannot do it from within the remote device on which I am currently ssh'ed? (Closing it when leaving seems more intuitive to me than having to ssh back in just to close it.) Commented Jun 1, 2023 at 16:12
0

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

1
  • 5
    so basically you are saying ControlPersist works only by keeping the ssh processes running in the background? Commented Nov 29, 2012 at 16:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.