Mac SSH

How to create an alias for ssh clients on Mac

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

 cd ~/.ssh

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.

ssh config

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.

alias

Now, run the below command to load the alias.

 source ~/.bash_aliases

To view, your aliases run the alias command in your terminal and all your aliases will be listed.
pi40raspberrypi3A7E2019 08 0400 28 13 1

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.


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *