Connecting to Ubuntu Server using SSH Keys and Putty

This tutorial shows you how to connect to your Ubuntu server using ssh with keys. The advantage is that you can connect to your server without passwords. However, this is strongly not recommended because anyone with access to your private key can break-in to your server. So here it goes:

First install SSH server on the server if not already installed:

sudo apt-get install ssh openssh-server

For increased security change the SSH port to something else (Eg. 2222) by editing /etc/ssh/sshd_config (optional). The default port (22) would work as well.

sudo nano /etc/ssh/sshd_config

Save and restart server.

sudo /etc/init.d/ssh restart

Then navigate to the following folder:

cd ~/.ssh

Generate a pair of keys:

ssh-keygen -t dsa

You could also use "rsa" instead of "dsa". When asked for a file name you may provide a file name for the keys (Eg. passkey) or just press enter for default naming. You may also choose to enter a passphrase for increased security (recommended). However, remember that you will have to enter this passphrase everytime to connect to the ssh server.

Then create a key file as described below and set its permissions.

touch authorized_keys
chmod 600 authorized_keys

Then add the public key (Eg. to the key file.

cat >> authorized_keys

Then for security remove the from the server.

Now logon to your other computer and move the other key (Eg. passkey) to this computer. In Ubuntu you can copy the private key (passkey) to the .ssh folder in your home directory. In Windows you can copy it to any folder.

In Ubuntu/Linux edit ~/.ssh/config file to use the private key for connections.

In Windows, use Puttygen.exe to load the passkey to generate a private key file. Use this key file while connecting to remote ssh server using Putty.

Hope this makes your job easier and fun!

Did this post help you?
SmartHomeBeginner brings in-depth tutorials easy enough to understand even for beginners. If you are reading this, please consider buying us a coffee (or two) as a token of appreciation.