Saturday, June 26, 2010

A script to do ssh easily

This is something which reduce my job a lot while working in my Linux box. While in work i have to connect to a lot of PC vi a ssh [secure shell]. And everytime i have to type"ssh root@172.xx.yy.zz " and then wait for the password prompt and then type the password. Ans sometimes it may not be root it might be some other user name but unnecessarily i need to repeat typing this "@172.xx" as this part is always common in a company. And most of the time I log in as root so i could avoid "root@172.xx." that saves a lot of energy; it seems 217 microjoules per keystroke; so its 217*11 mirojoules saving. So lets see the script which saves this energy.

if [ $#  -eq 0 ] //Check whether u have given any argument
echo "Input the lan ip for ssh"
elif [ $# -eq 1 ]    //check if argument is equal to one  [means default is root connecting]
echo "Connecting to 172.22.$1 as root"
ssh root@172.22.$1 -X
else "Connecting to 172.22.$1 as $2"  //take the second argument which is the username.
ssh $2@172.22.$1 -X

1)Name the file as c then [c for connect]
2)Store this file under /usr/bin may be with a name C. [so that u can access this like command]
3)Run the command
4)chmod 711 [group and others will get only execute access]

So now i have to type to connect ssh
c yy.zz   [to connect ssh root@172.xx.yy.zz]
c yy.zz username [to connect ssh username@172.22.xx.yy.zz]

This code if provided with 2nd argument which is considered as username then it will connect to that username else it will connect to root.

So in this way i make my work easier.

No comments:

Post a Comment