Use Public Keys for SSH sessions

By Tim Quax on 02 september 2009
Public keys are damn useful to use in automatic backups for example, in which you use SCP to throw around tarballs containing your precious data. It's also useful for sys admins that log onto their servers every 10 minutes, and your getting tired of the password prompts.

Open up a terminal for the server that needs to create an SSH session to another server. Log in with the user that needs to do the SSHing.

Generate a public key with the following:

ssh-keygen -t rsa

You'll be prompted for a few things; first is a password to attach to the public key (which is unnecessary, you'd still have your password prompt). The last prompt is for the file it saves the key in. The given default is fine.

Read out the public key:

cat ~/.ssh/id_rsa.pub

Copy the output and open up a session to the server that you need to SSH to, with the user that may receive SSH sessions without password prompts.

Open the following file (with any editor you like):

vi /root/.ssh/authorized_keys

Add the id_rsa.pub dump you copied to the file, and make sure it's on 1 line.

Then you're done! Now you can SSH from one place to another with the specific usernames without a password prompt.




React on this article







Enter the code here: