Tired of always typing your password when logging in to your server? Here are steps on how to you can eliminate the typing of your password and making it more secure when connecting to your server.
In this example scenario, let's call your local computer "mars" with user happy. We'll call the remote server "jupiter" with user happy (this can be any user in jupiter).
First in mars, fire up the console type the following command:
[happy@mars ~] ssh-keygen
You will be asked to specify where the key should be saved and optionally add a passphrase (aka password). Just hit enter key on those question. No need to enter a passphrase because it will beat our purpose.
The command will produce 2 files in /home/happy/.ssh folder. A private key which is used by the ssh program when connecting to remote hosts and a public key which needs to reside in the remote hosts.
We will now need to send the public key to the remote hosts.
[happy@mars ~] scp .ssh/id_rsa.pub happy@jupiter:/home/happy/
You will be asked for your password and if successful your public key will be transferred to the remote server.
We now need to tell the remote server that that public needs to be trusted.
[happy@mars ~] ssh happy@jupiter
happy@jupiter's password:
[happy@jupiter ~] mkdir .ssh
[happy@jupiter ~] cat id_rsa.pub >> .ssh/authorized_keys2
[happy@jupiter ~] rm -f id_rsa.pub
[happy@jupiter ~] chmod -R 700 .ssh
TIP: If you have the same username in the local and remote server, you can omit the "happy@" when doing ssh command.
This may be the last time you will be typing your password. The first command will get you inside the remote server as you usually do. The second one copies your public key into the authorized_keys2 file. The third one deletes your public key. Lastly, the fourth command sets the authorized_keys2 permission correctly (you only need to do this once).
You are now set to password-less logins. Exit the remote server and try logging in again. It should not ask for your password any more.
Comments
blog comments powered by Disqus