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. passkey.pub) to the key file.

cat passkey.pub >> authorized_keys

Then for security remove the passkey.pub 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. This takes a considerable amount of work. If this post helps you, please consider supporting us as a token of appreciation:
  • Feeling generous? Become a Sponsor (discounted options) or a Patron. You will receive privileges on our Discord Server.
  • Just want to thank us? Buy us a Coffee or a Ko-Fi.
  • May be another day? Shop on Amazon using our links. Your prices won't change but we get a small commission.
  • Don't feel like spending? You can still show your support by sharing this post, linking to it in forums, or even commenting below.

Anand

Anand is a self-learned computer enthusiast, hopeless tinkerer (if it ain't broke, fix it), a part-time blogger, and a Scientist during the day. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs.