Preparing VPS for Web Development

Preparing VPS for Web Development
Photo by XPS / Unsplash

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
Create a new user on the VPS 
ssh webdeveloper@example.com
groups
sudo su
ssh using your newly created user and test that sudo works
sudo apt update && sudo apt -y upgrade
Update the server 
sudo apt install nano
(Optional) I like to use nano as my text editor. You can use vi if you're comfortable with it.
sudo nano /etc/ssh/sshd_config
Now to disable root login via ssh.
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 
Restart the SSH service and close the current ssh connection.
ssh webdeveloper@example.com
This should now fail with "ssh: connect to host example.com port 22: Connection refused"

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
New command to ssh to your server.

From now on you should ssh to your vps with the -p <port> switch and as your new user instead of root.

have fun