This document is meant to serve as a basic guide for hardening a Linux server.
sudo nano /etc/ssh/sshd_config- Uncomment
#Port 22and change it toPort <SSH_PORT>. (Replace<SSH_PORT>with your desired port to use for SSH connectivity.) sudo systemctl restart sshreboot
sudo ufw default deny incomingsudo ufw default allow outgoing- Allow inbound traffic on specific ports:
sudo ufw allow <SSH_PORT>/tcpsudo ufw allow 443/tcp
sudo ufw enablesudo ufw status numberedsudo ufw reload
sudo adduser --disabled-password <USERNAME>sudo usermod -aG sudo <USERNAME>
mkdir -p /home/<USERNAME>/.sshchmod 700 /home/<USERNAME>/.sshcp ~/.ssh/authorized_keys /home/<USERNAME>/.ssh/chown <USERNAME>:<USERNAME> /home/<USERNAME>/.ssh/chown <USERNAME>:<USERNAME> /home/<USERNAME>/.ssh/authorized_keyschmod 600 /home/<USERNAME>/.ssh/authorized_keys
If you are using your new account for a form of automation, you may need require that it not require a password for running commands that require sudo.
sudo visudo- Add
<USERNAME> ALL=(ALL) NOPASSWD: ALLto the bottom of the file.
-
sudo nano /etc/ssh/sshd_config- Change
PermitRootLogin yestoPermitRootLogin no. - Change
#PubkeyAuthentication yestoPubkeyAuthentication yes. - Chage
#PasswordAuthentication yestoPasswordAuthentication no. - Change
#PermitEmptyPasswords notoPermitEmptyPasswords no. - Change
#StrictModes yestoStrictModes yes. - Change
#MaxAuthTries 6toMaxAuthTries 3. - Change
#MaxSessions 10toMaxSessions 3.
- Change
-
sudo systemctl restart ssh -
reboot
If your newly created account needs to be able to run docker commands, you will want to create a docker UserGroup and adde your user to it.
sudo groupadd dockersudo usermod -aG docker <USERNAME>