Server Hardening

This is the minimum list of hardening and other steps that need to be performed to secure the Linux server containing the DIVOC platform. The assumption is that the installation happens on a bare metal setup. While the concepts remain the same, the methodology might differ for commercial cloud setups.

Check for open ports

  • Identifying open connections to the internet is a critical mission.

circle-info

netstat -antp

  • Once you have identified the open ports, you can stop/purge the applications which keep unnecessary ports open.

  • The only acceptable open ports are 22 and 443. Access to the other ports outside the Kubernetes network should be prohibited.

  • All ingress should be routed through the 443 port only as needed.

Secure SSH

SSH is secure, but we need to harden this service as well. If we can disable SSH, then the problem is solved. However, if we want to use it, we have to change the default configuration of SSH. Password-based authentication should be disabled and only key-based authentication should be allowed. The steps for creating sudo users with public and private keys are as follows:

  • Create a non-root sudo user

circle-info

adduser <user>

  • Add the user to sudo users group

circle-info

usermod -aG sudo <user>

  • Login to the machine as the user

circle-info

su - <user>

  • Create SSH directory with appropriate permissions

circle-info

mkdir -p $HOME/.ssh chmod 0700 $HOME/.ssh

  • Generate a key pair for the protocol, and run:

circle-info

ssh-keygen -t ed25519 -C "My key for DIVOC server"

  • Share the public key created with users you expect to connect to the server

circle-info

$HOME/.ssh/id_ed25519.pub

  • You can modify your SSH configuration to be more secure by performing the following changes to the configuration file:

circle-info

nano /etc/ssh/sshd_config

  • Make sure that root cannot login remotely through SSH

circle-info

PermitRootLogin no

  • Allow some specific users

circle-info

AllowUsers [username]

  • Enable public key-based authentication and disable password-based authentication

circle-info

PubkeyAuthentication yes PasswordAuthentication no

  • There are some additional options that must exist in the “sshd_config” file: MaxAuthTries 5

  • Finally, set the permissions on the sshd_config file so that only root users can change its contents:

circle-info

chown root:root /etc/ssh/sshd_config

chmod 600 /etc/ssh/sshd_config

Creative Commons Licensearrow-up-rightAll content on this page by eGov Foundationarrow-up-right is licensed under a Creative Commons Attribution 4.0 International Licensearrow-up-right.

Last updated