If you are using SSH to login into many servers, it can be difficult to remember all the different usernames, hostnames, and IP addresses. I am going to show you how easy it is created to create command-line shortcuts also called as aliases to solve this problem. There are two methods to create an alias.
Method 1. By using ssh config
The first step is to navigate to your .ssh folder
Following this, you’ll need to create a file called config. Enter the below command.
sudo nano config
In this file, you can now create your own shortcuts by specifying the hostname and username. Below is an example of the file structure.
Now, you will be able to login by typing ssh <username> in the terminal without entering the password.
Method 2. Create an alias in shell
You can use this method to create an alias for your shell (or terminal). A lot of people use this method to create SSH shortcuts. The first step to navigate to your .bash_aliases file. The following command will create the .bash_aliases file if it doesn’t exist or just edit it if it already does use nano or vim.
sudo nano ~/.bash_aliases
In this file, you can add as many shortcuts as you want.
Now, run the below command to load the alias.
Now, you will be able to login by entering the username in the terminal.
TIP: To store the alias permanently add the alias in the .bash_profile file.
I hope, you find this useful. Please let me know your views on this.