Alias Command in Linux: How To Save Your Time With It

Do more by less

Yang Zhou
TechToFreedom

--

A woman on the sea
Image from Wallhaven

If you handled cloud servers before, you probably have the same feeling:

It’s easy to use the ssh command to connect to a remote server. But it’s painful to always input the location of the key file on your terminal.

For example, if you connect to an AWS EC2 server through ssh, you have to input a long command as follows:

ssh -i /Users/yang/projects/blog/servers/Keys/server1.pem  user@ip

What makes it worse is that you can’t remember the full path all the time. So sometimes you may have to change the path and input a similar command again.

The good news is, there is a command called alias that can save your time and make your life easier. 🙂

As its name implies, the alias can help you save a long command as an alias.

Basically, its syntax is as follows:

alias name="command"

In the above case, you can define an alias for the long command:

alias toServer="ssh -i /Users/yang/projects/blog/servers/Keys/server1.pem  user@ip"

That’s it. Now, you can just input toServer on the terminal and it will connect to your server successfully.

--

--