HomeTutorsContact
commandline
Initial Server Setup with Ubuntu 22.04
Konrad Kuśmierz
Konrad Kuśmierz
June 21, 2023
1 min

Table Of Contents

01
Step 1 — Logging in as root
02
Step 2 — Creating a New User
03
Step 3 — Granting Administrative Privileges
04
Step 4 — Setting Up a Firewall
05
Step 5 — Enabling External Access for Your Regular User
Initial Server Setup with Ubuntu 22.04

Step 1 — Logging in as root

To log into your server, you will need to know your server’s public IP address. You will also need the password or the private key for the root user’s account if you installed an SSH key for authentication.

ssh root@your_server_ip

Step 2 — Creating a New User

Once you log in as root, you’ll be able to add the new user account. In the future, we’ll log in with this new account instead of root. This example creates a new user called unuser, but you should replace that with a username that you like:

adduser unuser

Step 3 — Granting Administrative Privileges

usermod -aG sudo unuser

Step 4 — Setting Up a Firewall

ufw app list
Output
Available applications:
OpenSSH

You will need to make sure that the firewall allows SSH connections so that you can log into your server next time. Allow these connections by typing:

ufw allow OpenSSH

Now enable the firewall by typing:

ufw enable

Type y and press ENTER to proceed. You can see that SSH connections are still allowed by typing:

ufw status
Output
Status: active
To Action From
-- ------ ----
OpenSSH ALLOW Anywhere
OpenSSH (v6) ALLOW Anywhere (v6)

Step 5 — Enabling External Access for Your Regular User

ssh unuser@your_server_ip

Note: The rsync command treats sources and destinations that end with a trailing slash differently than those without a trailing slash. When using rsync below, ensure that the source directory (~/.ssh) does not include a trailing slash (check to make sure you are not using ~/.ssh/).

If you accidentally add a trailing slash to the command, rsync will copy the contents of the root account’s ~/.ssh directory to the sudo user’s home directory instead of copying the entire ~/.ssh directory structure. The files will be in the wrong location and SSH will not be able to find and use them.

rsync --archive --chown=unuser:unuser ~/.ssh /home/unuser

Tags

Share

Konrad Kuśmierz

Konrad Kuśmierz

Software Engineer

Founder

Expertise

devops
ai

Social Media

instagramtwitterwebsite

Related Posts

Install and Use Docker on Ubuntu 22.04
Install and Use Docker on Ubuntu 22.04
June 21, 2023
4 min