Latest Article

Casbay News

Promotions

Casbay Events

Tips Sharing

aaa

Stay tuned with us

SSH Key Exchange

How to Configure a Secure SSH-Based

Introduction

SSH is a remote connection method, whether or not it is a VPS. It is versatile and multi-platform, allows you to almost monitor your computer, as you were, and it has many useful features.

Yet protection is an important focus in the modern world of IT, so I will share some details about how to ensure access to your ssh. You’ll build a couple of keys: public and private. Privacy is your secure key for protecting, safeguarding and sharing with no one. It’s used as a special user to mark you. Public is a key to be delivered to remote servers or services.

Accessions

You’ll need:
1) CentOS 7.4 VPS server
2) Basic knowledge how to edit files in Linux systems
3) Linux or Windows host machine, from which you access the VPS server.

Generating A SSH Key Pair on Your Host Machines

If your system, from which you access VPS, is Linux ( Fedora 25 system was used, as a typical home/workplace Linux system):
1) run ssh-keygen and follow on-screen instructions
“ssh-keygen”

SSH-command ssh-keygen
SSH command “ssh-keygen”

You can enter a specific location of storage (you can leave this as it is). You will also be asked for a password to secure the key by ssh-keygen. Although passwordless, as it is sometimes useful for different setups (automatic systems without user input), the password should be protected from your key and your key will only not allow an attacker to access the VPS-server even if your key pair is compromised.
Remember password. When you forget it, you can’t restore your key control.

SSH-password
Must Remember Password

2) Backup your keys on a secure, safe storage
3) run cat /home/vpsuser/.ssh/id_rsa.pub ( replace path with the one, you have actually used ) and copy the key.

4) You need to put a copied key as a new string into
`/root/.ssh/authorized_keys`
on your VPS server. It should look like this

SSH-command copy key as a new string on VPS server
SSH-command copy key as a new string on VPS server

Notice that each key starts as a separate string.
5) To connect from linux machine to your VPS server through ssh, you just need to run
“ssh -i /home/vpsuser/.ssh/id_rsa.pub root@”

Connect from linux machine to VPS server through SSH
Connect from linux machine to VPS server through SSH

If your system, from which you access VPS, is Windows ( Windows 10 was used, as a typical home/workplace Windows system): 1) Run puttygen tool, that comes out of the box with a putty installation.

SSH-PuTTY Key Generator tool
PuTTY Key Generator tool

Press “generate” and it will ask you to move mouse on the empty area to generate random data, and will provide you an ssh key pair.

SSH-PuTTY tools key in info
SSH key pair

2.1) Enter password to “Key passphraze” and confirmation fields. Remember the password.
2.2) Copy the contents of the “public key for pasting into Openssh authorized_keys file:”
2.3) Save public and private key to a secure, safe storage

3) Copy’s the contents of the “public key for pasting into Openssh authorized_keys file:” windows in puttygen
4) Go back to your VPS server. We need to add the public part of the key pair, we have just created to the list of authorized keys. Put a copied key as a new string into
/root/.ssh/authorized_keys
On your VPS server. It should look like this

SSH-add the public part of the key pair on VPS server
add the public part of the key pair on VPS server

Notice that each key starts as a separate string.
5) Test connection to your VPS server
5.1) Open putty and go to Connection – SSH – Auth in the left panel.
5.2) Open you private key file by pressing Browse near the Private key for authentication field.

SSH-PuTTY private key file
Open Private Key File for authentication field

5.3) Go back to Session in the left panel of putty, enter your server hostname or ip with a login name ( optional, as putty will prompt for it anyway ) and press Open.

SSH-PuTTY Configuration-hostname or IP
Enter your server Hostname or IP

5.4) Putty will prompt for key password at it’s screen, and if entered correctly, forward you to your VPS server console

PuTTY-prompt for key password
PuTTY-prompt for key password

 

Securing Your SSH Server

Using Linux and Windows, you can now easily connect to your VPS server. You should currently disable access to your machine with a password, so any attempts to bruteforce are useless. Without an authorized ssh key your system will just not accept an incoming ssh connection. Open on your VPS server
“/etc/sshd/sshd_config”
and change “PasswordAuthentication yes” string to “PasswordAuthentication no” restart sshd daemon
“systemctl restart sshd”
and check that it has no problems
“systemstl status sshd”

Securing Your SSH Server
Securing Your SSH Server

 

Conclusion

Securing your link to your ssh-key pair and preventing a password login are a fundamental measure of security. It protects your server against a lot of attacks based on alphabetical password and bruteforce searches. In conclusion, secure at least basic steps for your VPS server to allow you to sleep better.