Saturday, May 4, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 2832  / 1 Year ago, mon, january 23, 2023, 11:21:16

I have a question to which I haven't been able to find an answer. I have two computers, both of which run Ubuntu 12.04. I keep one of my computers at home and use SSH to connect to it from the other ("remote") computer. The remote computer is able to connect to the home computer without problems. The remote computer also has SetAliveInterval set to 60 in /etc/ssh/ssh_config, so that the connection doesn't die if I step away from the computer for a moment.



Occasionally, my internet connection on my remote computer gets interrupted. Internet interruptions cause my SSH tunnel to close (of course). When I restore internet connectivity and re-connect to the home computer using a new SSH tunnel, though, I can see using #ps ax that the old SSH connection process is still running. This is a problem because I use an encrypted home directory on the home computer, which doesn't allow the files to be re-encrypted until that (now-dead) SSH connection is killed.



Is there a way to set sshd_config on the home computer so that it automatically detects when a connection has died, and terminates it?


More From » ssh

 Answers
5

Try screen or tmux. On the server side, or both sides if you like:



sudo apt-get install tmux


After logging in, start tmux.



tmux


If the connection breaks, log in again via ssh and reconnect the tmux session.
To discover the session number:



tmux ls


The output might be something like this:



0: 1 windows (created Tue Dec 25 19:20:40 2012)



Connect to the tmux numbered session like this:



tmux attach -t 0


Then you are right back where you left it. You won't have to kill the sessions. They just wait for your next visit. Or, if you just want to kill the session...



On the server side, see the /etc/ssh/sshd_config setting for ClientAliveInterval and ClientAliveCountMax. (man 5 ssh_config)



ClientAliveInterval 300
ClientAliveCountMax 0


Once they have been changed to your preference, restart the SSH server.



sudo /etc/init.d/ssh restart


The 300 is seconds (five minutes).


[#33517] Tuesday, January 24, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
losbu

Total Points: 71
Total Questions: 124
Total Answers: 106

Location: Honduras
Member since Sat, Jul 24, 2021
3 Years ago
losbu questions
Mon, Jan 31, 22, 21:41, 2 Years ago
Tue, Nov 22, 22, 01:27, 1 Year ago
Wed, Jan 25, 23, 00:28, 1 Year ago
Wed, May 11, 22, 08:41, 2 Years ago
;