18 May2016
How to create SSH shortcuts / aliases
Managing multiple servers can be very time consuming. Fortunuately, there are small tasks which makes this process much easier. In this quick tutorial, I will show you how to create SSH shortcuts / aliases in Linux.
Say for example that the servers which you are managing has the following hostnames:
- server1.dcname.domain.com
- server2.dcname.domain.com
- server3.dcname2.domain3.com
You get the idea.. if you had to do something via a for loop, this would be very tedious i.e.
for test in server1.dcname.domain.com server2.dcname.domain.com server3.dcname2.domain3.com ; do ssh root@$test command here ; done
Let's create the shortcut file.
Step 1
Browse to your .ssh directory.
cd /root/.ssh/
Step 2
Create the config file.
vi config
Step 3
Add your shortcuts to the config file.
host server1
hostname server1.dcname.domain.com
host server2
hostname server2.dcname.domain.com
host server3
hostname server3.dcname2.domain3.com
Save and exit the config and you are ready to use your shortcuts i.e.
for test in server{1..3} ; do ssh root@$test command here ; done
Looks much better doesn't it? Enjoy your extra time!