Home » Operating Systems » Connecting to Ubuntu Server using SSH Keys and Putty

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!

We Are Hiring: Familiar with Media Streaming, HTPC, Home Server, Smart Home, and Home Automation topics? Write about it and earn money. No writing experience needed. APPLY HERE.

Get 20% OFF with IPVanish VPN:

♦   Hide your browsing and streaming activity: No logs and no tracking
♦   Access geo-restricted content from anywhere
♦   Encrypt and anonymize: Kodi, Plex, Downloads, Personal Info
♦   Windows, Mac, Linux, Android, iOS, Router, and more.
♦   Money back guarantee - Sign Up Now

About the author

Anand

Anand is a self-learned computer enthusiast, a part-time blogger, and a Food Scientist by career. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs on htpcbeginner.com and smarthomebeginner.com.

Archives

Join the other 110,000 followers