Mac OS X Terminal - Naming SSH Connections?
The short question is that I'd like to know if it is possible to give ssh connections 'friendly' names in terminal?
My long reasoning is...
I've got several server clusters running behind a single IP address via NAT. I can SSH into the individual servers in each cluster with different port numbers e.g:
ssh clust1 -p 2210
ssh clust1 -p 2220
ssh clust1 -p 2230
In Putty/Windows I would give each connection a different name (clust1-web1, clust1-web2, clust1-web3), but in Terminal I cannot see a way to do this. This poses a problem because I cannot differentiate the server I'm connecting to by hostname, and the port numbers are somewhat random.
Solution 1:
Run this from the terminal:
nano ~/.ssh/config
and then you can insert your hosts like so:
Host clust1-web1
Hostname clust1
User Username
Port 2210
Host clust1-web2
Hostname clust1
User Username
Port 2220
Then you can ssh by simply running:
ssh clust1-web1
For a full list of arguments you can place in this file you can run:
man ssh_config
Solution 2:
it's not quite the same but you can save each connection command as an alias.
Or if you some how can't do it this way, just store each connection command as a shellscript/bashscript perhaps named connect-clust1-web1 and store those in a folder which is also in your PATH
so you're able to just type connect-clust1-web1 and you'll get connected.