How to Login to Linux Server with SSH key from Windows

Introduction

In this post I will show you how to login to your Linux Server with SSH key from Windows using PuTTY. PuTTY is an open source software and SSH and telnet client developed for the Windows platform.

I will connect to CentOS 7 (Linux) VPS server with SSH key from Windows operating system using PuTTY client.

Prerequisites

In order to connect to remote server with SSH key pair using PuTTY you need to generate private/public SSH key pair. You can find the tutorial Manually SSH key generation in Windows to generate SSH key pair.

Add Public Key to Linux Server

Read the following steps to setup the public SSH key in Linux server generated using PuTTYgen utility for a particular user, for example, roytuts.

  • Open Putty by double clicking on PuTTY.EXE.
  • Enter your server’s IP address and port. The default port is 22 if you have not changed it.
login to linux server with ssh key from windows
  • Click on Open button at the bottom right.
  • Now when you get the blank window input username (roytuts) followed by password.
  • Now you are in user’s home directory. Create a new directory called .ssh by executing the command $ mkdir .ssh. Note you don’t need to type $ as it is already there.
  • Restrict the permission of directory .ssh by executing the command $ chmod 700 .ssh.
  • Now create a file in .ssh directory called authorized_keys with a vi editor. This vi editor is by default available in the Unix based CentOS 7 system. Execute command $ vi .ssh/authorized_keys to create the file.
  • Now you will see that the file authorized_keys has been opened once created. Now press i to enter INSERT mode. Without INSERT mode you won’t be able to write anything in this file.
  • Now copy public key which you generated using PuTTYgen utility and paste into it by right clicking on the file editor.
  • To save and exit from the file editor, type :wq from your keyboard.
  • Now restrict the permissions of the authorized_keys file with the command $ chmod 600 .ssh/authorized_keys.

You are done setting up with your public in remote Linux server (CentOS 7).

In this section we have seen how to connect to Linux server using password and we also setup the public SSH key in the user’s home directory. The next section will guide you how to connect to Linux server using SSH key pair. This time you don’t need to put user’s password but passphrase which you set during public/private key generation.

Connect to Linux Server using SSH Key

Go through the following steps one by one to connect to Linux server:

  • Open Putty by double clicking on PuTTY.EXE.
  • Enter your server’s IP address and port. The default port is 22 if you have not changed it.
  • Make sure you select SSH radio button.
  • Now click on Connection -> SSH -> Auth. Browse and select file for loading the private key which you saved during public/private key pair generation using PuTTYgen utility.
login to linux server with ssh key from windows
  • Now click on Open button to connect to remote server. You will now see black window where you need to enter your username followed by passphrase (password) you had set during public/private key generation using PuTTYgen utility.
login to linux server with ssh key from windows
  • Now you can see the terminal where you can execute commands as per your needs to perform certain operations.

That’s all. Hope you got how to connect to Linux server with SSH key pair using PuTTY from Windows environment.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *