How to use ssh username alias to log in as a different user


The alias feature of bash is very powerful if you use it effectively, let us explore how to use it for remote login
Code:
admin@devopsrun~$ ssh root@devopsrun01
Last login: Sat Nov  2 03:44:55
[root@devopsrun01 ~]#

Using bash function


Define a bash function to alias your username for remote server login:
Code:
function sshr(){ ssh devops@$@; }
Example:
Code:
admin@devopsrun~$ function sshr(){ ssh devops@$@; }
admin@devopsrun~$
admin@devopsrun~$ sshr devopsrun01
devops@devopsrun1's password:

To make this available permanently:


Edit your .bashrc
Code:
vi ~/.bashrc
Add the below line
Code:
# remote login using devops
function sshr(){ ssh devops@$@; }

Next time when you login, sshr will be available to ssh with your chosen username(in this example devops).