2. Secure SSH Connection
SSH access is the most standard attack vector for an online server. An incredible number of robots and hackers scan the default port 22 and gain access, with basic and elaborated credentials.
In this part, we are going to build a secure SSH connection with strong SSH keys. We will change the default SSH port to mitigate scans and brute-force attempts.
We will use the curve25519-sha256
protocol (ECDH over Curve25519 with SHA2) for our keys here as this is considered the most secure nowadays.
This part is a modified version of bLd's guide using only Putty client to access server. If you are using Linux or MacOS, you can refer directly to the original guide to use Open SSH.
Configuration
Follow this guide step-by-step. We recommend that you try to understand every step explained in this guide.
Be very careful to never close your actual session until you’ve tested the connection with your new key. You could lose access to your SSH connection.
Connect to your server using PuTTy.
- Open PuTTY
- Type the IP of your server on Azure in the field called ‘Host Name’.
- The terminal will open and you can log in with your username and password.
Let’s start by moving our actual unsecured host keys into a backup directory:
cd /etc/ssh
sudo mkdir backup
sudo mv ssh_host_* ./backup/
Open the ssh
config file:
sudo nano /etc/ssh/ssh_config
Add the following lines in the Host *
section and save:
Host *
KexAlgorithms curve25519-sha256@libssh.org
HostKeyAlgorithms ssh-ed25519-cert-v01@openssh.com,ssh-ed25519
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512,hmac-sha2-256,umac-128@openssh.com
PasswordAuthentication no
ChallengeResponseAuthentication no
PubkeyAuthentication yes
UseRoaming no
Save CTRL+O
your file and close the editor CTRL+X
Open the sshd
config file:
sudo nano /etc/ssh/sshd_config