Computing

Creating SSH key access to your Linux VPS

Typical SSH connection is with username and a password, without adding extra security that leaves the server open to brute force or access from anyone who can read your printed password in plaint text such as emails or a text file.

Having SSH key access to your server adds extra door/s of protection, plus instead of needing a password potential hackers now need a key and a password.

You can generate keys on your Linux server but for ease for beginners this will use windows and PuTTY Gen. PuTTY (popular SSH client) for windows can be downloaded here. In this package comes PuTTY Gen.

Generating your keys

Search for the PuTTY Gen.exe and open it

open PuTTY Gen

Click generate

Wave your mouse around in the area to speed up the process

Generate key PuTTY Gen

You now have your key

Create/enter a password to protect the key file

Create password for key

Save the public and private key in safe place with a name you can recognize. I usually do hostnamePUBLIC and hostnamePRIVATE.

Add key to server

Open PuTTY.exe (or any SSH terminal) and connect to your server with the usual username and password.

Create the ~/.ssh directory with

mkdir -p ~/.ssh

Then create and open ~/.ssh/authorized_keys file with

nano ~/.ssh/authorized_keys

Here you want to paste the public key output from PuTTY Gen as seen by this highlighted top part (right click select all and then copy).

PuTTY Gen copy public key

Once pasted into ~/.ssh/authorized_keys do ctrl + x then y and enter to exit and save.

Close the connection

Connect to server with key

Open up PuTTY and put in your servers hostname

enter hostname PuTTY

On the list at the left find Auth under the SSH sub menu, click it.

Where it says Private key file for authentication click browse and select your private key you just generated.

SSH Auth add private key PuTTY Gen

Click session at the top of the list, where is says saved session enter a name (hostname) and click save.

create session and save PuTTY Gen

To connect simply find the name you just used, click load and then open.

Enter your username and the password for the key file and you will now be logged in.

login with key PuTTY

It is recommended to disable the normal username password login method after you have finished this key based authentication.

 

Share

Recent Posts

Kennington reservoir drained drone images

A drained and empty Kennington reservoir images from a drone in early July 2024. The…

1 year ago

Merrimu Reservoir drone images

Merrimu Reservoir from drone. Click images to view larger.

1 year ago

FTP getting array of file details such as size using PHP

Using FTP and PHP to get an array of file details such as size and…

2 years ago

Creating Laravel form requests

Creating and using Laravel form requests to create cleaner code, separation and reusability for your…

2 years ago

Improving the default Laravel login and register views

Improving the default Laravel login and register views in such a simple manner but making…

2 years ago

Laravel validation for checking if value exists in the database

Laravel validation for checking if a field value exists in the database. The validation rule…

2 years ago