I have to connect to a base server, call it server1, and the from there, I can access many other servers (host1, host2, ...host99.) I have the autossh working for server1 with no problems - it restores my connection to server1 anytime my network connection is lost. However, staying connected to server1 is not my only goal. I want to stay connected to host1, 2, etc. when I'm using those machines.

I just use this to get to server1:

autossh server1

Right now, when I try to autossh to host1, I get:

local autossh[867] <Error>: bind on Address already in use

Now, the setting for my monitoring port is just 12345 (in ~/.bash_profile):

export AUTOSSH_PORT=12345

...so it looks like the localhost port 12346 is tried next but fails.

My ~.ssh/config has this forwarding setup:

Host server1
  User jacob
  HostName server1.mydomain.com
  Port 722
  ForwardAgent yes
  LocalForward 1124 1:22
  RemoteForward 52698 #for sublime text / rmate
  IdentityFile ~/.ssh/id_rsa

Host host1
 User jacob
 HostName localhost
 RemoteForward 52698
 Port 1124
 ForwardAgent yes
 IdentityFile ~/.ssh/id_rsa

....I've read everything I could find about the "Address already in use" error and tried modifying my config file, adding hosts to the etc/hosts file, still the same result. Any ideas?

1 Answer 1


According to man autossh (the manual page), with the monitoring port specified in a single number, autossh uses both that port and port+1 for its monitoring function, where the latter is called its "echo port" (for receiving the monitoring response). That means it will listen on port+1, and thereby claim that port. A subsequent autossh program must be given different ports.

Alternatively you may use port 0, which turns off the connectivity test, and then just restarts ssh should it exit. Quoting the manual page:

Setting the monitor port to 0 turns the monitoring function off, and autossh will only restart ssh upon ssh's exit. For example, if you are using a recent version of OpenSSH, you may wish to explore using the ServerAliveInterval and ServerAliveCountMax options to have the SSH client exit if it finds itself no longer connected to the server. In many ways this may be a better solution than the monitoring port.

  • Thanks, that worked. I read that part of the man page and thought the lack of monitoring would kill the intended functionality of reconnecting, but apparently the monitoring feature is distinct from auto-reconnect.
    – JacobIRR
    Commented Apr 25, 2016 at 23:10

You must log in to answer this question.

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