SSH is a very repetitively used tool in development. Save time and keystrokes with these tips and tricks.

SSH Config

Having an SSH config file is a great way to speed along the process of tunneling into a server by remembering the more exceptional connection details for you and supplying autocomplete for the ssh command.

You can also override the default id_rsa identity file used by the ssh command. Take a look at the example:

IdentityFile /Users/kevindees/.ssh/id_rsa_dev

# Simple Example
# This is a simple example.
Host cd-dev-site-01
  User username
  Port 22222

# Bastion or Proxy Jump
# This example server does not have its SSH port 22222
# open to the internet. This servers SSH port is only
# open to other servers in a closed network. We can
# use another server cd-dev-site-01 as a Bastion^1
# to SSH into that server and use the ProxyJump
# config argument to automatically SSH into a
# on a connection  
Host cd-live-site-01
  User username
  Port 22222
  ForwardAgent yes
# Custom Identity File
# Use an identity file other than the default.
Host cd-live-site-02
  User username
  Port 22222
  IdentityFile /Users/kevindees/.ssh/id_rsa_alt

Here we set the default identity file to /Users/kevindees/.ssh/id_rsa_site and we defined serveral ssh shortcuts. Now, when entering ssh into the terminal we will gain auto complete for cd-dev-site-01, cd-live-site-01, and cd-live-site-02.

You ssh config file is located under your ~/.ssh/config directory. If you do not have a config file yet create one as ~/.ssh/config.

SSH Agent

Use SSH Agent. You can avoid entering your ssh password multiple times during a proxy jump by using ssh-agent with your identity file. As an added benefit ssh-agent will keep you from needing to add your identity file to your servers when you SSH into them.

Github has published a great article about SSH agent on their website.


^1 Bastion