Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have multiple notebooks and workstations which pull and push from multiple Mercurial repositories on a central server. I usually use .ssh/config to set an alias:

Host repo-server
HostName server.somedomain
User user143
IdentityOnly yes
IdentityFile ~/hgkey
Port 156

... and some more options, you get the idea. I can then simply do a hg push ssh://repo-server//hgroot/someproject on every local repository, and I can change the server address and port in one place.

For workstations, this works fine, but the notebooks can access the server either from inside the network or from outside, using a different address and a different port. Is there any way I can specify multiple HostName/Port combinations so that SSH automatically tries them in order? This way, the users could push and pull without having to care about the correct address.

(of course, using a VPN would be the most correct solution)

share|improve this question
up vote 4 down vote accepted

I'm afraid that is not possible with SSH.

You could possibly work around this using the ProxyCommand option of ssh, along with a custom script that creates a TCP connection to a server (using netcat), depending on how/where your notebook is connected. Something along the lines of:

SSID=$(/sbin/iwgetid wlan0 -r)

case "$SSID" in
  nc <host1> <port1>
  nc <host2> <port2>
  nc <host3> <port3>

Then, in your .ssh/config, you would need the following:

Host repo-server
  User user143
  IdentityOnly yes
  IdentityFile ~/hgkey
  ProxyCommand path-to-script
share|improve this answer
Guess I'll write a script which modifies the HostName entries then. Thank you. – leoluk Jun 22 '12 at 13:24

Another alternative could be to set up a script to forward the ssh port 22 of the “right” ip to some unused local port of your laptop and then ssh there. I use it in quite a number of situations.

share|improve this answer
This is not at all clear without an example. – Andrew Schulman May 9 '15 at 7:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.