Using RSA keys to login to a remote computer via SSH without using a password

I tend to remotely login to various different computers through SSH a lot. Typing my password every time I login to a remote machine gets tiresome. This is how to generate public/private key pairs so you don't have to enter your password every time you login through ssh!

First, some terms.

The client computer is the computer you will be logging on from.

The server is the computer where you will be logging on to.

On the client, open a terminal and type:

$ ssh-keygen -t rsa

You will be asked where to save the keys to. Just hit enter to save the keys to the default location (~/.ssh/id_rsa and ~/.ssh/id_rsa.pub). When it asks for a passphrase to use, just leave it blank and hit enter (this way we won't need a password). Protect your private key! Now you're going to want to copy your public key to the server. Login to the server and create a ~/.ssh directory:

$ mkdir ~/.ssh

Copy the public key from the client to the server:

$ scp ~/.ssh/id_rsa.pub server:~/.ssh/clientname

Be sure to replace 'server' with the server name or address and 'clientname' with the name of your client box. On the server, go to your ssh directory:

$ cd ~/.ssh

If an authorized_keys file doesn't exist, make one now:

$ touch authorized_keys

Change the permissions of the authorized_keys file:

$ chmod 600 authorized_keys

Now copy the key from the client box into the authorized_keys file:

$ cat clientname >> authorized_keys

Again, make sure to replace 'clientname' with the name you gave the file. Now you should be able to ssh from your client box to your server box without having to enter a password. Make sure you protect your private key. If anyone gets a hold of your private key, they will be able to connect to the server box as you!****

Meta

Published: July 28, 2008

Author: jmhobbs

Word Count: 314

Tags

linux mac

  • Tag Cloud

  •  

    Copyright © 2015 Jared Hobbs. All rights reserved. Powered by Pelican. The Hobbs Family theme available here.