1

I'm using macbook and annoyed by ssh timeout everyday.

When my internet connection is down(by moving to conference room) or most of the times that macbook goes to sleep mode, ssh connections show timeout message Timeout, server ~~~~ not responding. after 10~15 seconds, and any key input including Ctrl+zxcd all does nothing before timeout.

How can I change this, so instead of waiting 15 seconds to re-open ssh or relaunching terminal to open another ssh connection that I can get timeout message & get disconnected after 3 seconds?

Here's my ~/.ssh/config file... yeah I've tried ServerAliveInterval but it didn't work.

Host git-codecommit.*.amazonaws.com
  User ABCDEFGHICJKLMNOPQRST
  IdentityFile ~/.ssh/id_rsa
Host *
  ServerAliveInterval 3
  ConnectTimeout 3
  ConnectionAttempts 1

Also my /etc/ssh/ssh_config is modified that it contains only comments. (Because of bash: warning: setlocale: LC_CTYPE: cannot change locale (UTF-8): No such file or directory.)

To reproduce this, ssh any remote host and then turn Wifi off.

  • @nohillside Thank you, but I've already tried that but nothing in that post does not work. I created an EC2 instance and connected to it using public ipv4(so no DNS lookup), and added all sshconfig variables in ~/.ssh/config but it still waits too long after network disconnected. I updated ~/.ssh/config in my question. – ik1ne Nov 23 '18 at 8:28
1

You need to set ServerAliveCountMax as well. The system works so that it after a timeout of "ServerAliveInterval" seconds, it sends a packet and tries for "ServerAliveCountMax" times before timing out completely.

So add:

ServerAliveCountMax 1

to the settings!

I would also recommend taking a look at mosh instead of regular SSH. This will enable you to keep the same connection to the server even between wakes, moves to the conference room, etc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .