SSH is a commonly used remote-access solution. The popularity of various cloud based solutions brings “some challenges” in the usage of SSH to remotely access the servers in the could. Because, you might have a lot of VMs in the cloud, and they might have different IP address/URL, username and passport. This would become a nightmare if you only know the “elementary” SSH commands.
In this post, we will introduce you some “advanced” SSH configurations. For ease of presentation, we assume you have two VMs in the cloud, their identities are as follows:
Note that, unless explicitly stated, we assume all the configurations are on your local computer.
Please refer to Play with Github
Copy the content of your public key and add it to the end of the file ~/.ssh/authorized_keys
on VM A (note that if the file does not exists, you need create one.).
Similarly, upload SSH public key to VM B.
Add the following content at the end of your ssh configuration file, i.e., ~/.ssh/config
Host A
HostName hostA.com
User userA
IdentityFile path/to/ssh-private-key
Host B
HostName hostB.com
User userB
IdentityFile path/to/ssh-private-key
Now, you can remotely access VM A simply by ssh A
.