Problem
To connect to a remote server, I use ssh -p8520 username@remote host.
Issue:
When I’m at work, it’s always connected and working correctly. Unfortunately, after connecting to the remote server from home, the terminal freezes after 10 – 15 minutes.
Although there is no error or timeout report on the console, the cursor is no longer able to move.
When I type w to check the login users, I get a list of zombie login users, which I have to manually kill.
This is quite inconvenient. Is there anyone who can assist me?
Asked by Haifeng Zhang
Solution #1
If the client stays silent, the ssh daemon (sshd), which operates on the server, ends the connection (i.e., does not send information). Instruct the ssh client to send a sign-of-life signal to the server every so often to avoid connection loss.
The configuration for this can be found in the file $HOME/.ssh/config; if it doesn’t exist, create it (the config file must not be world-readable, so execute chmod 600 /.ssh/config after creating it). Put the following in the configuration file to transmit the signal to the remote host every, say, four minutes (240 seconds):
Host remotehost
HostName remotehost.com
ServerAliveInterval 240
Place the following text in the configuration file to enable sending a keep-alive signal to all hosts:
Host *
ServerAliveInterval 240
Answered by rockymonkey555
Solution #2
I was looking for a one-time fix:
ssh -o ServerAliveInterval=60 myname@myhost.com
I saved it as an alias:
alias sshprod='ssh -v -o ServerAliveInterval=60 myname@myhost.com'
Now you can connect in the following way:
me@MyMachine:~$ sshprod
Answered by Ryan
Solution #3
For those who are curious, @edward-coast
If you want to keep the server alive, add the following to /etc/ssh/sshd config:
ClientAliveInterval 60
ClientAliveCountMax 2
Answered by Jeff Davenport
Solution #4
Users of Putty can change the options here.
Answered by Ruben Benjamin
Solution #5
The following global configurations will keep our ssh connection active.
In the /etc/ssh/ssh config file, add the following line:
ServerAliveInterval 60
Answered by minhas23
Post is based on https://stackoverflow.com/questions/25084288/keep-ssh-session-alive