Setting up a new server is a crucial step in ensuring the security and functionality of your system. Ubuntu 22.04 is the latest long-term support (LTS) release from Canonical, and it comes with a variety of features and improvements. In this guide, we will walk you through the essential steps of the initial server setup on Ubuntu 22.04.
Disable Root Access #
One of the first steps in securing your server is to disable root access. The root user has superuser privileges, and allowing direct access to it can pose a significant security risk. To disable root access, follow these steps:
- Log in as a user with sudo privileges: First, log in to your server as a user with sudo privileges. If you don’t have a user with sudo access yet, you can create one (as explained in the next section).
- Edit the SSH configuration file: Open the SSH configuration file using a text editor like Vim or Nano. For example:
sudo nano /etc/ssh/sshd_config
- Disable root login: Find the line that says
PermitRootLogin yesand change it to
PermitRootLogin no. This will prevent the root user from logging in directly.
- Save and exit: Save the changes and exit the text editor.
- Restart SSH service: To apply the changes, restart the SSH service:
sudo systemctl restart sshd
Root access is now disabled, and you should use a regular user account with sudo privileges for all administrative tasks.
Create a Regular User Account #
Creating a regular user account is essential for maintaining security and managing your server efficiently. To create a new user with sudo privileges, follow these steps:
- Create a new user: Replace
<username>with your desired username:
sudo adduser <username>
- Set a password for the user: You’ll be prompted to set a password for the new user.
- Grant sudo privileges: To give the new user administrative privileges, add them to the sudo group:
sudo usermod -aG sudo <username>
You now have a new user account with sudo privileges that can be used for server administration tasks.
Install Utilities: Vim and Screen #
While Ubuntu comes with a range of pre-installed tools, you may want to install additional utilities to improve your server’s functionality and ease of use. Two commonly used utilities are Vim (a text editor) and Screen (a terminal multiplexer). You can install them with the following commands:
- Install Vim:
sudo apt update sudo apt install vim
- Install Screen:
sudo apt update sudo apt install screen
With Vim, you have a powerful text editor at your disposal, and Screen allows you to create and manage multiple terminal sessions, which is especially handy when working remotely.
Install a Firewall #
Firewalls are crucial for server security as they control incoming and outgoing network traffic. Ubuntu 22.04 uses
ufw (Uncomplicated Firewall) by default, which simplifies firewall management. To install and configure
ufw, follow these steps:
- Install ufw:
sudo apt update sudo apt install ufw
- Enable ufw:
sudo ufw enable
- Allow essential services:
- Allow SSH for remote access:
sudo ufw allow OpenSSH
- If your server hosts other services (e.g., web server), allow those ports as needed.
- Enable ufw:
sudo ufw enable
Your firewall is now active and configured to allow essential traffic while blocking unauthorized access. Remember to adjust the rules as necessary to match your specific server setup.
In conclusion, setting up a new server with Ubuntu 22.04 involves several crucial steps, including disabling root access, creating a regular user account with sudo privileges, installing essential utilities like Vim and Screen, and configuring a firewall to enhance security. Following these steps will help you establish a secure and functional server environment for your needs.