General OS Hardening (Ubuntu 20.04 LTS)
ssh root@yourIPaddressPatching Software
sudo apt update
sudo apt upgradeMaking New User
You will disable the root user becasue you have sudo
adduser "you"Add that user to sudo group
usermod -aG sudo "you"Change the logged root to create an account
su - usernameCheck to see if your user is part of sudo group
sudo whoamiIf it returns root you now have sudo privlages
exit
exitNow move the root account and log out of ssh. Log back in with the created user account.
ssh user@yourIPaddressLocking root
Remove the root account from logging to ssh
sudo nano /etc/ssh/sshd_configFind "PermitRootLogin" and change to "PermitRootLogin no"
Save and exit
Now restart ssh
sudo service ssh restartMake sure if you try to log in with root again you get "permission denied"
Change ssh port and lockout policy
Check if firewall is enabled
sudo ufw statusType in this if it is active
sudo ufw allow sshIf you changed the port add this one too
sudo ufw allow ---Now change the port
sudo nano /etc/ssh/sshd_configUncomment these lines and type in
Port ---
MaxAuthTries 5You can change the max tries if need be. If the password is wrong more than 5 times it will lock out you IP address
Save and Exit
Restart ssh
sudo service ssh restartTo log back in you need to
ssh user@yourIPaddress -p "yourport"SSH Settings
sudo nano /etc/ssh/sshd_configFirst thing you are going to enable is Protocol 2

sudo system restart sshTimeout Idle value
If you're AFK while connected to ssh there could be an issue. You can decrease or increase the time you can be idle.
ClientAliveInterval 180Last updated
Was this helpful?