Before we dive into the specific options and wild cards that you can use, let’s first make sure you have an SSH config file set up. This file is located at
~/.ssh/config and is used to store all of your ssh connection settings.
If you don’t have this file already, you can create it by running the following command:
Once you have your config file set up, you can start adding entries for each of the servers that you frequently connect to. A basic entry will include the hostname and the username that you use to log in, like this:
Now, every time you want to log into the server at
example.com as the user
johnsmith, you can simply run
ssh example from the command line.
Using Options for All or Individual Hosts
One of the most useful features of the SSH config file is the ability to set options for all hosts or specific individual hosts. This can save you a lot of time and typing in the long run.
For example, let’s say that you always use the
-X flag to enable X11 forwarding when you ssh into a server. Instead of typing this flag every time you connect, you can set it as a global option in your config file like this:
Now, every time you ssh into any server, the
-X flag will be automatically included in the command.
If you only want to set an option for a specific host, you can do so by adding the option after the hostname in your config file, like this:
-X flag will only be included when you ssh into the
Using Wild Cards
Another handy feature of the SSH config file is the ability to use wild cards to match multiple hosts. This can be especially useful if you have multiple servers that follow a similar naming convention.
For example, let’s say you have multiple servers that are named
server3, etc. Instead of creating a separate entry for each server, you can use a wild card like this:
Now, whenever you want to ssh into any of these servers, you can simply run
ssh server2, etc. and the correct hostname and username will be automatically included in the command.
5 Tips for Improved Productivity
- Use options to set frequently used flags as global or host-specific options to save time and typing.
- Use wild cards to match multiple hosts with similar naming conventions.
- Consider using the
ProxyCommandoption to connect to servers through a bastion host or jump box.
- Set up SSH key pairs to avoid having to enter passwords every time you log in.
- Use the
Includeoption to include other configuration files in your main config file, allowing you to separate out different groups of servers for easier management.
Test Your Knowledge
Now that you’ve learned about optimizing your SSH config file, it’s time to put your knowledge to the test. Try setting up a config file for three servers that you frequently connect to, using a combination of options and wild cards. Share your final config file in the comments below!