A VPS, or “Virtual Private Server,” can be an excellent choice for hosting your website. It will allow you to use a server without incurring the costs of purchasing your dedicated server and maintenance contracts.
This article is going to teach you how to set up a VPS with Ubuntu 22.04, including setting up SSH key-based authentication, a firewall, timezone, updating Ubuntu 22.04, and creating swap space and remote desktop via VNC.
Create User With Superuser Privileges
The first step to setting up an Ubuntu VPS (after you get it from the hosting provider) is to create the user(s) that will be performing admin actions on the server. Like most Linux servers, you should create a user with superuser (or “root”) privileges. You can run commands as root or use sudo to execute commands as a different user without typing the password every time.
It is important to note that once you create the user, any files and directories (such as /home and tmp) will be owned by your new user. You must also set permissions on those directories to be writable by your user account.
Set Up SSH Key-Based Authentication
While you could also use an FTP or SCP server to log in to your VPS, sometimes it’s just easier to use SSH for everything. Setting up SSH key-based authentication allows you to log in without a password and with high levels of security by using the public/private key method.
Set Up Firewall
The next step is to put a firewall in place. This will keep out attackers and malware from your VPS. You can use iptables for this, as it is the most basic form of firewall configuration on Linux.
Step One: Install iptables. On Ubuntu, you can do this with apt-get by running the command:
sudo apt-get install iptables
Check The Timezone
Once you have your firewall in place, you will want to check the timezone of your server. By default, Ubuntu’s timezone setting is UTC (Coordinated Universal Time) based on Greenwich Mean Time (GMT). To change the timezone of your server, open a terminal and run this command:
If you just want to see the current time in your current working day, replace “date” with “man date.” Replacing “man date” with “man date -s” will give you a list of all available options.
Update Ubuntu 22.04
Ubuntu doesn’t have a package update tool by default, so that we will use the Aptitude application. Open a terminal and run the following command:
sudo apt-get update
This will download the latest package information from Ubuntu’s repositories and compare them with what is installed on your server. If you see any packages that need upgrading, change “update” to “upgrade” in this command to install them automatically.
For security reasons, it is recommended that you turn automatic updates off even though they are very convenient. To do this, run this command:
sudo dpkg-reconfigure – priority = low unattended-upgrades
Create Swap Space
To run the larger processes on your VPS, you will want to use a swap file. Swapping (also called swapping space) is a feature of Linux that allows the virtual disks to be used as RAM if possible, thus freeing up disk space for running programs.
This is where programs run without using all of your system’s RAM. To create a swap file, open a terminal and type the following command:
sudo dd if = /dev/zero of = /swapfile bs = 1M count = 2048
This will create a file named “swapfile,” which will be 20 MB in size. You can check the free space on your hard drive by running this command:
You should see that it shows as “20 MB” and your capacity, which is likely less than what you have available.
Remote Desktop With VNC
VNC is a great way of connecting to your VPS from another computer. It allows you to control the server with a program that you can run on your computer (or mobile device). To configure VNC for Ubuntu, open up “Terminal” and type this command:
sudo apt-get install vnc4server vnc4client
To set up your VPS as an “access point,” simply click the “Host with password” button and enter your password when prompted.
Configure A Web Server
Once you have a remote desktop in place, you can configure a web server to host your website on your VPS with Ubuntu 22.04. Because you will require high levels of security, this is best done with a self-hosted web server such as Apache.
To set up Apache and create a “default” virtual host, open a terminal and type the following:
sudo apt-get update sudo apt-get install apache2
This will bring in all of the necessary components to get your web server up and running. You can create your “default” virtual host now that you have those components installed. To do this, open a terminal and run the command:
sudo a2dissite 000-default
This will disable the default site so we can start fresh when creating our own.
Set Frequent Backups
You should have a functional VPS ready to host your website. Before you move on to installing WordPress, one of the last steps is to set up backup schedules.
Depending on the type of content you choose to host and how much traffic it gets, backups can take up a lot of space and cut into your monthly storage quota. Backups are very important if hackers break into your server and delete or modify files.
To set up backups, go back to your terminal and run this command:
sudo apt-get install rsync
This will download all necessary components for setting up an automated backup schedule.
The Bottom Line
It’s very important that you understand all of the steps involved in setting up a VPS. While some methods can be skipped, they will require different levels of experience and education to complete successfully.
For example, if you choose not to set up a firewall and turn off automatic updates, you will want to run in the root user to you don’t need to enter a password every time you want to make changes.
To keep your VPS running well, it is also crucial that you keep your system updated so that your programs are running at their maximum efficiency. Keep in mind that many applications like Apache will require specific versions of PHP or other components for everything to run properly.
If you don’t know how to set up and manage a VPS and want the hosting provider to do it for you, check out a managed VPS provider.