Skip to content

Instantly share code, notes, and snippets.

@midir99
Last active March 13, 2026 16:15
Show Gist options
  • Select an option

  • Save midir99/a07c35a86d6ed60de6797394af17143b to your computer and use it in GitHub Desktop.

Select an option

Save midir99/a07c35a86d6ed60de6797394af17143b to your computer and use it in GitHub Desktop.
Set up Ubuntu VPS

Set up Ubuntu VPS

These are some steps that I follow when I provision a small VPS for myself.

1. Add my user

I SSH into the VPS and add my user.

NEW_USER=midir99
# Add user
adduser $NEW_USER
# Add user to sudoers group
usermod -aG sudo $NEW_USER
# Enable user lingering
loginctl enable-linger $NEW_USER

2. Set up SSH key to log in

I set up an SSH key for more security.

On my local machine

# Create the key with a secure passphrase
ssh-keygen -t ed25519
# Print and copy the public key
cat id_ed25519.pub

On the VPS, paste your public key at ~/.ssh/authorized_keys

On my local machine, update ~/.ssh/config for faster log in

Host vps
    HostName vps-ip.com
    User midir99
    Port 22
    IdentityFile /home/midir99/.ssh/id_ed25519

Validate the key login is configured correctly by running on your local machine: ssh vps

3. Disable root login and password authentication

I disable them for more security

On the VPS,
Edit the /etc/ssh/sshd_config
Set PasswordAuthentication no
Set PermitRootLogin no

4. Set up the firewall

On the VPS run

ufw allow 22/tcp
ufw enable
ufw status

5. Set up your timezone

# Find your timezone using
timedatectl list-timezones
# Then set it
timedatectl set-timezone America/New_York

6. Install fail2ban

apt install -y fail2ban
systemctl enable fail2ban
systemctl start fail2ban

That's it, feel free to add recommendations, complains, comments, questions, demands, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment