Skip to content

Instantly share code, notes, and snippets.

@elmahdim
Last active May 26, 2022 19:55
Show Gist options
  • Save elmahdim/b08490841a76cb1067fd82453b141bca to your computer and use it in GitHub Desktop.
Save elmahdim/b08490841a76cb1067fd82453b141bca to your computer and use it in GitHub Desktop.
Initial settings for linux VPS hosting

Update and upgrade apt packages

  • Before going any further, update & upgrade apt (advanced package tool) packages
# 👉 remote terminal

apt update && apt upgrade

Fail2ban

Fail2ban is an intrusion prevention software framework that protects computer servers from brute-force attacks. Read more

# 👉 remote terminal

apt install fail2ban -y    ℹ️ `-y` stands for yes
systemctl enable fail2ban
systemctl start fail2ban
systemctl status fail2ban  ℹ️ Verify that fail2ban is active
reboot

Set up a firewall with UFW

UFW, or Uncomplicated Firewall, is an interface to iptables that is geared towards simplifying the process of configuring a firewall.

# 👉 remote terminal

sudo apt-get install ufw
sudo ufw status
sudo ufw enable

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 80   ℹ️ HTTP
sudo ufw allow 443  ℹ️ HTTPS
sudo ufw enable

Configure the OpenSSH server

Go to and edit sshd_config file

# 👉 remote terminal

vim /etc/ssh/sshd_config # 📝 use vim or nano

Edit as showing below

# 👉 remote terminal

- PermitRootLogin Yes
+ PermitRootLogin no

- Port 22
+ Port XXX ℹ️ Set your custom port number

Restart configs

# 👉 remote terminal

systemctl restart sshd

Non-root user

  • Create a non-root user
# 👉 remote terminal

adduser XXX # ℹ️ Replace XXX with your own user name
password    # ⚠️ Do not use your root password
exit        # ℹ️ Required for the next step
  • Verify newly created user
# 👉 remote terminal

ssh XXX@**.***.**.** # ℹ️ You'll be asked for your user's password (not root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment