Friday, September 28, 2007

Is your Linux server farm growing? If you are like me you manage a large number of Linux servers using your Linux desktop terminal for ssh access. With such a large number of linux servers how nice would it be to just ssh directly to your server without having to authenticate every time. Infact how would you like to have one server that has the ability to run scripts against any server at any time using ssh without having to authenticate.

Here are some easy steps to make login simple using ssh.

First generate your ssh key, I prefer an rsa key; well because it's an rsa key.
user@linuxbox~:>ssh-keygen -t rsa
ssh-keygen will generate our key, to specify the type use the -t option for type, and of course set the type to rsa. Next you will be asked where to put the key, I leave it as defaut. The next question that comes is for a passphrase, just a hint leaving this blank and just hitting enter makes using ssh much easier but less secure.

Now that we have our rsa key in /home/user/.ssh/id_rsa.pub, we should also log in as root and make a key for root also. The nice thing about root having ssh access is that if we are root we don't have to put a userid in our ssh command. You could always create a user with the same name as your user account also on all the machines to take care of this issue.

Copy the ssh key you generated over to your servers. This is done with the ssh copy command.
user@linuxbox~:>ssh-copy-id -i ~/.ssh/id_rsa.pub root@server
You will be prompted for root's password on the server you are copying your certificate to, but once your cert is copied over you will no longer have to put in roots password.

Now use ssh to login to your server.
user@linuxbox~:>ssh root@server
notice that you did not need a password, and you are now in to your server. In fact you can run your commands remotely for example.
user@linuxbox~:>ssh root@server cat /etc/HOSTNAME
you will notice that the server you issued the ssh command to returns the command. This becomes very usefull if you want to write remote scripts, or even run backups, or copy. You can also use the scp command now without authentication.

No comments: