1. User Management
Running commands as the `root` user is dangerous. The first step is always creating a new user and granting them administrative privileges.
Create a new user
adduser new_username
The system will prompt you to enter and confirm a password. You can skip the additional informational fields by pressing Enter.
Grant Sudo Privileges
Add the newly created user to the sudo group so they can execute administrative commands:
usermod -aG sudo new_username
2. Securing SSH Access
By default, SSH allows password authentication. Switching to SSH keys and disabling root password logins drastically reduces vulnerability to brute-force attacks.
Edit SSH Configuration
Open the SSH daemon configuration file:
sudo nano /etc/ssh/sshd_config
Find the following lines and modify them accordingly:
# Disable root login via password (keys still work if configured)
PermitRootLogin prohibit-password
# Ensure password authentication is allowed for normal users
PasswordAuthentication yes
Restart SSH Service
Apply the changes by restarting the service:
sudo systemctl restart ssh
Note: Always test your connection in a new terminal window before closing your current root session!
3. Basic UFW Firewall Setup
Ubuntu's Uncomplicated Firewall (UFW) provides an easy-to-use interface for managing iptables.
Allow SSH Connections
Before enabling the firewall, you must allow SSH traffic, otherwise you will lock yourself out of the server:
sudo ufw allow OpenSSH
Enable the Firewall
sudo ufw enable
sudo ufw status
4. Package Management & Updates
Keep your server secure by regularly updating the local package index and upgrading installed software.
Update & Upgrade
sudo apt update && sudo apt upgrade -y
Remove Unused Packages
Clean up dependencies that are no longer needed:
sudo apt autoremove -y