SSH is a popular network protocol used to access remote computer through certain network or internet. OpenSSH is an application which provides SSH accesbility for a computer or server. Common method used to start a communication with SSH access is by providing username and password before secured connection is established. This method is not really safe because you provide credentials in plain text and transfer it through the network. It also makes any scumbag individuals to be easier to guess your password or perform brute force attack in order to gain your server access. There are several possible ways that I think can be used for hardening your SSH security.
- Disable root access
- Change SSH port number
- Utilize RSA authentication
- Disable plain password login
Disable root access1) Before you disable the root access, you need to make sure that there are another user account in your remote computer.
2) Create new user as needed.
$ adduser youruser3) Edit SSH configuration in
/etc/ssh/sshd_config. Set new value for several following properties.
PermitRootLogin no AllowUsers youruser
AllowUsersproperty is optional. It is used only for limiting access to certain users. You can add more users by separating it using space in the value.
4) Restart SSH service.
$ service sshd restart
Change SSH Port NumberYou can change
Portproperty other than 22.
Utilize RSA Authentication1) Generate private and public key in your local computer. I prefer to use PuTTYgen because it can generate not only OpenSSH-compatible key but also PuTTY-compatible key. PuTTY is a common application for remote access available for Windows. It needs certain format of private key with .PPK extension. PuTTYgen is included in PuTTY installation.
2) Open PuTTYgen. Set number of bits in generated key (2048, 4096, etc). Click "Generate".
3) After process was completed, you can get 4 types of key. First, in the big text box, it is OpenSSH-compatible public key. Copy the content, paste it to text editor (e.g. Notepad) and save it as id_rsa.pub. Second, you possibly need to fill the key passphrase. It adds more security to your private key. Click "Save public key" and save it as id_rsa.putty.pub. Third, click "Save private key" and save as id_rsa.ppk. It's PuTTY-compatible private key. Fourth, choose "Conversion" menu then choose "Export OpenSSH key". It will generate OpenSSH-compatible private key and save it as id_rsa.
4) Now, back to OpenSSH configuration in remote server. Set new value for several following properties.
RSAAuthentication yes PubkeyAuthentication yes AuthorizedKeysFile %h/.ssh/authorized_keysThe last property means that OpenSSH application will check any allowed public keys stored in the user authorized_keys file.
5) Copy your user OpenSSH-compatible public key content and append it to
.sshdirectory should be owned by your user and set its mode to 0700 for security while the
authorized_keysmode should be 0600.
6) Back to local computer and open your PuTTY application. On Session menu, insert your remote computer address with its user and port. Then, go to Auth menu, choose your PuTTY-compatible private key. Then, back to Session menu and save your configuration.
Disable plain password loginBefore you implement this configuration, you must make sure that previous process is working. By setting
PasswordAuthenticationvalue to "no" will make your server can be accessed only by RSA authentication.
If you think this article is usefull, you can share it. Or, if you have any suggestion or question, please leave it on comment below.