Introduction:
Upon the creation of a new Ubuntu 22.04 server, prioritizing essential configuration steps is pivotal for enhancing both security and usability. These initial measures lay a robust foundation for subsequent actions, ensuring a seamless server management experience.
Step 1 — Accessing as Root:
To initiate server access, familiarity with the server’s public IP address and either the root user’s password or private key is imperative. If unacquainted, a detailed guide on SSH connectivity is available. Log in as the root user using the command:
ssh root@your_server_ip
Ensuring a secure connection.
About Root: Given the root user’s elevated privileges, regular use is discouraged due to the potential for unintentional, destructive changes. The subsequent step involves creating a new user account with limited privileges for day-to-day activities.
Step 2 — Creating a New User:
After logging in as root, the creation of a new user account is facilitated. Replace ‘sammy’ with your preferred username:
adduser sammy
Provide a robust password and optional additional information.
Step 3 — Granting Administrative Privileges:
While the new user possesses regular privileges, administrative tasks sometimes require root privileges. To circumvent constant user switching, grant superuser privileges using
usermod -aG sudo sammy
This enables running commands with administrative privileges using sudo
.
Step 4 — Setting Up a Firewall:
Leveraging the UFW firewall on Ubuntu 22.04 ensures controlled access to specific services. Tailor firewall settings as needed, starting with allowing SSH connections:
ufw allow OpenSSH
Activate the firewall with:
ufw enable
Type y
and press ENTER
to proceed. You can see that SSH connections are still allowed by typing:
ufw status
The output for you when testing:
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)
Note: You can examine the list of installed UFW profiles by typing:
ufw app list
Output:
Available applications:
OpenSSH
Step 5 — Enabling External Access for Your Regular User:
Configure SSH access for the new user based on root authentication method. If using password authentication, SSH into the new user account with:
ssh sammy@your_server_ip
For SSH key authentication, replicate the root user’s .ssh directory to the new user using rsync
. Connect securely using ssh sammy@your_server_ip
.
You will be prompted for your regular user’s password when using sudo
for the first time each session (and periodically afterward).
You should be connected to your server with the new user account without using a password. Remember, if you need to run a command with administrative privileges, type sudo
before the command like this:
sudo command_to_run
Also read: How To Install WordPress on Ubuntu with a LAMP Stack
Conclusion:
These meticulously curated steps not only bolster your server’s security but also establish an efficient user management framework. Following these guidelines ensures a secure and streamlined Ubuntu 22.04 server environment for both novice and experienced users alike.