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!

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

    Post new comment

    Google Friend Connect (leave a quick comment)
    Loading
    The content of this field is kept private and will not be shown publicly.
    • Web page addresses and e-mail addresses turn into links automatically.
    • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
    • Lines and paragraphs break automatically.

    More information about formatting options

    CAPTCHA
    This question is for testing whether you are a human visitor and to prevent automated spam submissions.
    4 + 0 =
    Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.