ssh in to your Debian Pogoplug without a Password

OpenSSH allows you to run commands on a remote server from your desktop machine as well as just logging in to that server without requiring a password. This also means you don’t have to store the remote system’s password in the script. That makes it ideal for automating common tasks with shellscripts and cronjobs. In particular it allows you to use keep a webdav folder synched with one on your desktop similar to the way dropbox works.

To enable the remote login you create a pair of keys, one of which you simply append to a file upon the remote system. When this is done you’ll then be able to login without being prompted for a password – and this also includes any cronjobs you have setup to run.

To generate a rsa type keypair, run the following command from a terminal on your local machine:

ssh-keygen -t rsa

This will prompt you for a location to save the keys, and a pass-phrase as follows:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):

Press enter to save it in ~/.ssh/id_rsa

The program will then prompt you for a passphrase which should be blank. Therefore press enter twice, once for the passphrase and once to confirm your blank passphrase.

At that point, you’ll have a pair of files key files (public and private) with no passphrase. This means that the key files can be used as they are, without being “unlocked” with a password first.

Next, you need to append the contents of the .pub file to the correct location on the remote server.

Assuming that you wish to login to the machine called remoteserver from your current host with the id_rsa and id_rsa.pub files you’ve just generated you should run the following command:

ssh-copy-id -i ~/.ssh/id_rsa.pub serverusername@remoteserver

This will prompt you for the login password for the server, then copy the keyfile for you, creating the correct directory and fix the permissions as necessary.

The contents of the keyfile will be appended to the file ~/.ssh/authorized_keys2

Once this has been done test it by logging in:

desktopusername@desktop:~$ ssh serverusername@server

should log you in without a password prompt.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: