Preparing VPS for Web Development
Requirements
- Unmanaged Virtual Private Server
- A Domain name (Optional)
- WSL2 or Git Bash or CygWin or a local install of openssh (Optional)
Assumptions
- domain name: example.com
- user name: webdeveloper
- VPS is newly acquired.
- We will be using WSL2 for this tutorial
It's always nice to start with a clean slate. Let's begin by (re)installing the VPS's OS. Choose an Ubuntu or Debian variant to be able to follow this Note. After installing the OS, let us take the first step to secure our VPS.
The easiest way to get compromised is to leave the root account active. So Let's disable root access via ssh and change the ssh port to make it difficult to guess.
First some preparations. Fire up the Terminal and run the following commands:
ssh root@example.com
useradd -m -s /bin/bash -G sudo,www-data webdeveloper
passwd webdeveloper
exit
ssh webdeveloper@example.com
groups
sudo su
sudo apt update && sudo apt -y upgrade
sudo apt install nano
sudo nano /etc/ssh/sshd_config
Look for the following lines and replace the values
- Port 22 => Port 5088
*** Replace 5088 with a port of your choice. - PermitRootLogin yes => PermitRootLogin No
Save the file
sudo service ssh restart
# OR if that fails
sudo systemctl restart ssh
exit
ssh webdeveloper@example.com
To ssh into your VPS you should add the -p 5088 switch which specifies the port your ssh daemon is waiting for connections.
ssh webdeveloper@example.com -p 5088
From now on you should ssh to your vps with the -p <port> switch and as your new user instead of root.
have fun