Showing posts with label ssh. Show all posts
Showing posts with label ssh. Show all posts

Saturday, November 20, 2010

Allowing multi-hop ssh

If you are trying to reach a server only accessible through another server, you will need to use ssh twice. This might cause mild irritation. Luckily, there is a recipe that can make things easier.

Assuming we are trying to reach hostnameB through hostnameA, add the following lines (after you put appropriate values for hostnames) to your SSH configuration in ~/.ssh/config

Host hostnameA
ProxyCommand ssh hostnameB nc hostnameA 22


For this to work, netcat needs to be installed on hostnameB, but many new systems have it, so you may have that too. Now, if you type, "ssh hostnameB" automatically you will first ssh to hostnameA and then hostnameB.

Stay logged in the server with ssh

Add the following lines to the ~/.ssh/config file and you will stay logged in the server. If you are trying to connect to your work machines from home, this might be a useful trick.

Host *
ServerAliveInterval 120
ServerAliveCountMax 3