This is a walkthrough of setting up agent forwarding to allow transparent access to computers on the other side of a gateway. The main reference is the awesome article An Illustrated Guide to SSH Agent Forwarding; see also SSH and ssh-agent for a more Unix-like approach. We will suppose that we are on the machine HOME, and that we want transparent access to the machine TARGET which we can only access via the machine GATEWAY. We proceed as follows:
- Generate a public/private key pair on HOME using ssh-keygen -t rsa -b 3072 (we need a bitsize of 3072 when using AES128).
- Copy the file HOME:.ssh/id_rsa.pub to the files {GATEWAY,TARGET}:.ssh/authorized_keys.
- Add the text command="sh -c 'ssh username@TARGET ${SSH_ORIGINAL_COMMAND:-}'" to the beginning of the file GATEWAY:.ssh/authorized_keys. (The SSH_ORIGINAL_COMMAND business is apparently needed for svn to work. It’s also supposed to make scp work, but unfortunately it doesn’t.) This is called a forced command.
- Finally add the following to the file HOME:.ssh/config, which will allow easy access to TARGET and, importantly, enable agent forwarding:
Host nickname_for_TARGET Hostname TARGET User username_for_TARGET ForwardAgent yes
Now to use this from HOME, we run ssh-agent and ssh-add in a terminal, and then running ssh nickname_for_TARGET should dump us directly onto TARGET.