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