SSH is a very repetitively used tool in development. Save time and keystrokes with these tips and tricks.
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
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 Hostname dev-01.example.com 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 # live-01.example.com on a connection Host cd-live-site-01 Hostname dev-01.example.com ProxyJump firstname.lastname@example.org:22222 User username Port 22222 ForwardAgent yes # Custom Identity File # # Use an identity file other than the default. Host cd-live-site-02 Hostname live-02.example.com 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
You ssh config file is located under your
~/.ssh/config directory. If you do not have a config file yet create one as
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.