How To Create SSH Alias In Linux

If you frequently access a lot of different remote systems via SSH, this trick will save you some time. You can create SSH alias to frequently-accessed systems via SSH. This way you need not to remember all the different usernames, hostnames, ssh port numbers and IP addresses etc. Additionally, It avoids the need to repetitively type the same username/hostname, ip address, port no whenever you SSH into a Linux server(s).

Create SSH Alias In Linux

Before I know this trick, usually, I connect to a remote system over SSH using anyone of the following ways.

I believe most of the newbie Linux users and/or admins would SSH into a remote system this way. However, If you SSH into multiple different systems, remembering all hostnames/ip addresses, usernames is bit difficult unless you write them down in a paper or save them in a text file. No worries! This can be easily solved by creating an alias(or shortcut) for SSH connections.

We can create an alias for SSH commands in two methods.

Method 1 – Using SSH Config File

This is my preferred way of creating aliases.

We can use SSH default configuration file to create SSH alias. To do so, edit ~/.ssh/config file (If this file doesn’t exist, just create one):

Again make sure you have replaced the host, hostname, port number and ip address with your own. Save the file and exit.

Then, apply the changes using command:

$ source ~/.bashrc

Or,

$ source ~/.bash_profile

In this method, you don’t even need to use “ssh alias-name” command. Instead, just use alias name only like below.

$ webserver
$ dns
$ dhcp
$ ubuntu

These two methods are very simple, yet useful and much more convenient for those who often SSH into multiple different systems. Use any one of the aforementioned methods that suits for you to quickly access your remote Linux systems over SSH.