98

Every time I connect to a server with ssh, the connection is reset after a few minutes if there is no input. However, I want to remove these timeouts as to keep the connection alive for as long as possible.

By looking on different forums, I saw it was possible to modify the ServerAliveInterval option in the /etc/ssh_config file. However, there doesn't seem to be this option in my file. Where could it be?

I'm running OpenSSH_5.2p1 on Snow Leopard.

Thanks!

Michael Eilers Smith
  • 8,466
  • 20
  • 71
  • 106

1 Answers1

165

Server Alive interval simply sends a null packet to the server at a set time to keep the connection alive, you should just be able to add some thing like into your config file: ~/.ssh/config

Host *
 ServerAliveInterval 60

The second line must be indented with at least one space. * will match any host; if you wanted you could restrict this to particular destinations like *somedomain.com.

Check out http://kehlet.cx/articles/129.html

Pavel Bucek
  • 5,304
  • 27
  • 44
Dominic Green
  • 10,142
  • 4
  • 30
  • 34
  • 1
    ok but where can I find this option. In which file? – Michael Eilers Smith Dec 28 '11 at 19:54
  • 7
    Just create a ~/.ssh/config file with something like the following (* will match any host, if you wanted you could restrict this to particular destinations like *kehlet.cx): Check out http://www.kehlet.cx/articles/129.html – Dominic Green Dec 28 '11 at 19:56
  • You should also be sure to indent the ServerAlive line with at least one space. – Jim Oct 19 '16 at 20:37
  • After I ssh to a remote host and then edit this config file, do I need quit the ssh connection and redo ssh again, or it will just works with existing ssh connection? – Sting Jia Oct 09 '18 at 06:43
  • 1
    @StingJia - It sounds to me like you misunderstood the answer. This is an ssh *client* setting, not an ssh *server* setting. It is something you would need to configure on each SSH client. Also, not that this answer naively assumes that you are running your ssh client on a UNIX-like operating system or sub-environment; if you are running something like PuTTY on Windows, you'll probably need to find and configure an analogous setting using different instructions. – Keith F. Kelly Jan 16 '20 at 19:07
  • link is dead .... – user5359531 Dec 08 '22 at 01:06
  • On a Mac, open a terminal and from any directory type > nano ~/.ssh/config (don't type the >, that represents the command prompt) – jasondeegan Jul 15 '23 at 23:46