Many of you know how to do password-less login with SSH.
Below is my approach.
person@NOVELLDESK:~> ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/home/person/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/person/.ssh/id_dsa. Your public key has been saved in /home/person/.ssh/id_dsa.pub. The key fingerprint is: 1e:05:de:d8:6a:10:3e:39:c2:ee:85:58:ec:56:1d:e9 person@NOVELLDESK person@NOVELLDESK:~> ssh-copy-id -i ~/.ssh/id_dsa.pub root@CREATIVEDESK Password: Now try logging into the machine, with "ssh 'root@CREATIVEDESK'", and check in: .ssh/authorized_keys to make sure we haven't added extra keys that you weren't expecting. person@NOVELLDESK:~> ssh root@CREATIVEDESK Last login: Fri Apr 11 12:52:31 2008 from 164.XXX.XXX.88 CREATIVEDESK:~ #
Now the magic will start from here.
For example, one often needs to log in to servers CREATIVEDESK, RED, GREEN, BLUE.
Step – 1:
Create a simple shell script in BASH, and save it as ‘ssh-to-server’ in ‘/usr/local/bin’. ‘sudo’ is your friend.
#! /bin/bash #Note: I am assuming that you have to login as root to #every server" > ssh root@`basename $0` $*
Step – 2:
Create Symbolic link of ‘ssh-to-server’ with the name of the server (Whose IP can be resolved)
person@NOVELLDESK:~>sudo cd /usr/local/bin person@NOVELLDESK:~>sudo ln -s ssh-to-server CREATIVEDESK person@NOVELLDESK:~>sudo ln -s ssh-to-server RED person@NOVELLDESK:~>sudo ln -s ssh-to-server GREEN person@NOVELLDESK:~>sudo ln -s ssh-to-server BLUE
Step – 3:
Now time to execute the magic…
Magic – 1
person@NOVELLDESK:~> CREATIVEDESK uptime 2:15pm up 31 days 0:35, 5 users, load average: 0.00, 0.00, 0.00 person@NOVELLDESK:~> RED uptime 2:15pm up 101 days 0:35, 3 users, load average: 0.00, 0.00, 0.00 person@NOVELLDESK:~> GREEN uptime 2:15pm up 252 days 0:35, 1 users, load average: 0.00, 0.00, 0.00
Magic – 2
person@NOVELLDESK:~> CREATIVEDESK ls -l /usr/bin total 82950 -rwxr-xr-x 1 root root 8929 Jun 19 2006 3Ddiag -rwxr-xr-x 1 root root 1314 Jun 19 2006 3Ddiag-result -rwxr-xr-x 1 root root 1828 Jun 19 2006 3Ddiag.devel ...
Magic – 3
Transferring Single file:
person@NOVELLDESK:~>cat foo | CREATIVEDESK cat > foo
Transferring Multiple files with archive in desire remote location.
person@NOVELLDESK:~>tar -c -f - bar | CREATIVEDESK "cd /tmp; tar -x -f -"
Now, one can simply ssh to server by giving only server name (whose IP can be resolved), and get it’s result. This will eliminate “AnyUserName@IP/ServerName” syntax login to server and then execute the command and Blah…Blah…
Don’t comment me on that SSH Alias tips and Tricks,
Believe in Art Of Administration!
That’s it for now…