How I Setup an Ubuntu Server
I have setup a lot of servers over the years. Here is how I setup an Ubuntu server. Quick and simple 🤘
When you first create a new Ubuntu server, you should perform some important configuration steps as part of the initial setup. These steps will increase the security and usability of your server and will give you a solid foundation for subsequent actions.
# Login as root
ssh root@your_server_ip
# Create new User
adduser sammy
# Add your user to the sudo
group
usermod -aG sudo sammy
# Setup Firewall
ufw allow OpenSSH
ufw allow https
ufw enable
If you have setup the firewall accordingly the output of ufw status
should look like the following.
ufw status
# output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
443 ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
443 (v6) ALLOW Anywhere (v6)
# Add SSH Key to .ssh/authorized_keys
In order to access the server as non-root user you need to add your public ssh key to the .ssh/authorized_keys
of the user you created above.
# Prevent Login with Password / Force SSH Key Pair Authentication
Open the file /etc/ssh/sshd_config
as root
and set the following values.
PasswordAuthentication no
PubkeyAuthentication yes
After you changed the ssh configuration you need to restart the SSH service.
# Prevent Login as root
Open the file /etc/ssh/sshd_config
as root
and set the following values.
PermitRootLogin no
After you changed the ssh configuration you need to restart the SSH service.
# Restart SSH Service
sudo systemctl restart sshd
# Don’t ask for Password when using sudo
Open the file /etc/sudoers
with root
with sudo visudo
and add the following to the end of the file.
YOUR_USER_NAME ALL=(ALL) NOPASSWD: ALL
# Sources
- Initial Server Setup with Ubuntu | DigitalOcean (opens new window)
- UFW Essentials: Common Firewall Rules and Commands | DigitalOcean (opens new window)
- Easiest way to copy ssh keys to another machine? (opens new window)
- How do I force SSH to only allow users with a key to log in? (opens new window)
- How To Disable Root Login on Ubuntu 20.04 | DigitalOcean (opens new window)
- How to Disable the Sudo Command Password | Step-by-step Guide (opens new window)