Go ahead and log into the console of your server and elevate your privileges to the root using or ‘su -i’ (or use sudo as below). First, lets make sure OpenSSH is already installed. If it’s already installed, these commands will upgrade it to the latest version.
sudo apt update
sudo apt install -v openssh-server
sudo yum install openssh-server --refresh
sudo dnf install openssh-server --refresh
This will either install/upgrade openSSH server or tell you that it’s already at the latest version. If you receive an error, there is likely a problem with your package management.
OpenSSH Configuration
The main configuration file for OpenSSH server is at /etc/ssh/sshd_config. Our final goal is to access the server using SSH keys. When you open the file in a text editor, lines that begin with a ‘#’ are ignored. The remaining lines are settings. Confirm these settings by uncommenting or changing them to look like the following:
If you login with a password:
PasswordAuthentication yes
usePAM yes
Allow root to log in using ONLY a key (no password):
PermitRootLogin prohibit-password