MacOS – How to keep connections alive on ssh MacOS Catalina

catalinamacmacossshterminal

I am trying to keep connections alive to my university server. It keeps disconnecting after 2-3 minutes of inactivity and it gets very frustrating to keep relogging in. I tried many things online but I am unable to edit any of the files.

I have tried following instructions here: https://www.a2hosting.com/kb/getting-started-guide/accessing-your-account/keeping-ssh-connections-alive

Perhaps the problem is that I dont have a ~/.ssh/config file – changes I try to make to the below given files, I keep getting this:

  1. — INSERT — W10: Warning: Changing a readonly file
  2. E45: 'readonly' option is set (add ! to override)
  3. "sshd_config" E212: Can't open file for writing

When I try to create it (copy and paste the command you use here), it says this:

mkdir: .ssh: Permission denied

I am happy to answer any further questions you may have 🙂

This is what my /etc/ssh looks like:

enter image description here

This is what ssh_config looks like:
enter image description here

and this is what my sshd_config looks like:
enter image description here

Is there a better guide to creating my ssh config so I can have my client ssh keep alive the connection to the server?

Best Answer

Catalina is same as all the older OS X and macOS for this. For you, it seems the hidden ssh folder is what’s stopping your attempt to configure the file. My commands make the directory and then clobber any file you may have so don’t use the cat > and expect to keep old file contents. You can then edit the file once it’s set.

mkdir -p ~/.ssh
cat > ~/.ssh/config << EOF
Host keepsdroppingme.com
ServerAliveInterval 120
EOF

Of course you need to put the host you care about having the 120 second keep alive traffic being synthetically generated whether you’re typing or not. On the server side, they can still enforce a timeout, but this often works wonders.