Play with SSH

  • Author:Long Gong
  • Last Edited:11-16-2016
  • Tags: ssh

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:

  • A
    • domain name: hostA.com
    • username: userA
    • password: passwdA
  • B
    • domain name: hostB.com
    • username: userB
    • password: passwdB

Note that, unless explicitly stated, we assume all the configurations are on your local computer.

Generate SSH key

Please refer to Play with Github

Upload SSH Public Key to VM A/B

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.

Configure Local SSH

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.

More Advanced Tricks To Be Appeared

  • Showing GUI
  • Showing GUI from a VM behind NAT
  • Creating SSH tunnels to “bypass” access gateway