Monday, September 2, 2013

Using your ssh config file to connect to a computer through a gateway.

At my school I have some public IP addresses and virtual machines for them to use for class projects. I enjoy connecting from home but I have to go through the school's ssh server to connect to a vm(virtual maching). Having to hop through the school's server every single time I want to connect can be cumbersome, and also makes it more difficult to send files to my vm, since I have to send the file to the ssh server, then connect to it and send it again to the vm.
The other day I started looking for a way to modify my ~/.ssh/config file to have it automatically go to the vm. I tried a few different things. Some didn't work and some weren't working because of a  mistake of my own. Finally I found how to make it work. My config file is set up like so:
Host school
HostName domain.name.of.school.ssh.server
User my_school_username

Host ns1
HostName <ip of my master nameserver>
ProxyCommand ssh school -W %h:%p

Host ns2
HostName <ip of slave nameserver>
ProxyCommand ssh school -W %h:%p

The computers ns1 and ns2 are the ones that are behind the school's ssh server, and school I set as the ssh server. the ProxyCommand lines let ssh know that every time I want to connect to ns1 or ns2 that I need to go through 'school'.
One problem I ran into was that I tried to use the HostName ns1 or ns2(since they are designated as such in the ssh config on the school server). That doesn't work. You have to put in the ip of the machine.

No comments:

Post a Comment