ssh is a great tool for remote access, especially under Linux. The command line based remote access can run smoothly on a slow network link.

Sometimes we access a remote machine so frequently that we want to get rid of the step of entering password every time. SSH actually allows key authentication, and it’s very easy to set up.

If you’re in a rush, a three-step quick guide is give below,

ssh-keygen –t dsa

cat ~/.ssh/id_dsa.pub | ssh remote_user_name@remote_ip “cat >> ~/.ssh/authorized_keys2”

ssh remote_user_name@remote _ip

For more details about each step, please read the explanation for each step below.

1. Generate Key Pair

Simple enter the following command,

ssh-keygen –t dsa

or, if you prefer rsa encryption,

ssh-keygen –t rsa

This will generate a public key (the file with .pub extension) and a private key (without .pub extension). You’ll need to put the public key to the remote side and keep the private key in a safe place.

2. Copy Public Key to Remote .ssh Directory

If remote server doesn’t have .ssh folder at home directory, run ssh-keygen on remote side to create one.

If there’s no authorized_keys2 file under .ssh folder, copy the public key to the remote side.

scp ~/.ssh/id_dsa.pub remote_user_name@remote_ip:~/.ssh/authorized_keys2

If there’s already a authorized_keys2 file, append the public key file content to the end of the authorized_keys2 file.

One can use a single command,

cat ~/.ssh/id_dsa.pub | ssh remote_user_name@remote_ip “cat >> ~/.ssh/authorized_keys2”

or execute the following steps.

First, copy the public key file to a temporary file at remote side,

scp ~/.ssh/id_dsa.pub remote_user_name@remote_ip:~/.ssh/tmpfile

Next ssh to remote side,

ssh remote_user_name@remote_ip

Finally, append the temporary file content to the end of authorized_keys2 file,

cat ~/.ssh/tmpfile >> ~/.ssh/authorized_keys2

3. SSH to remote Server without Password

Now you can ssh to remote side without password.

Note that if the first time you failed to ssh to remote side, you can simply log out from your computer and log in again. I don’t know why this works, but it fixes the issue.

 

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Set your Twitter account name in your settings to use the TwitterBar Section.