How to create, modify or delete a user in Ubuntu 24.04
Creating separate users on a server is an important step for security and rights management. Root access is not recommended for everyday tasks, as it increases the risk of irreversible problems. Moreover, you should not provide superuser data to third parties to perform any work not related to server software configuration. In this guide you will learn how to create a user yourself, configure its rights and provide secure SSH access to the server, as well as delete the user.Creating a user via terminal
To create a user, we can use two utilities: useradd or adduser.The adduser utility is the easiest way. It automatically creates a home directory, a group, asks for additional data, including a password, and creates a user.
As an example, let's create user01. For this purpose, having authorized on the server under the root user, use a simple command:
adduser user01
The command will give us information about creating a group, directory and ask for a password:
After specifying and confirming the password, there will be a number of additional questions, which you can safely skip by pressing Enter, and a request to confirm the correctness of the entered data:

Done. The user01 user was successfully created using the adduser utility.
Using the useradd utility we need to pass all the necessary information in the command parameters.
For example, let's do the same thing that adduser does automatically, but through useradd:
useradd -U -m -s /bin/bash user01
- -U - creates a group with the user name;
- -m - creates a home directory (/home/user01);
- -s /bin/bash - specifies the shell (bash);
- user01 - the name of your new user.
passwd user01
In the end you should get this picture (the screenshot also shows the list of user01 user groups to show that user01 group has been created):

Adding a user to a group, using sudo
To allow a new user to use the sudo command in Ubuntu 24.04 you need to add him to a group of the same name.This can be done using the usermod utility:
usermod -aG sudo user01
- -aG - adds to a group without removing from other groups;
- sudo - group name;
- user01 - username.
We can see that our user user01 now has a second group, sudo:

Now, while on the server under this user, you can execute commands as superuser using sudo by specifying the user's own password:

Password change settings
We have previously used the change user password command:passwd user01
Command to force password change when logging in as a new user for the first time:
chage --lastday 0 user01
You can force user01 to change his password regularly by setting the maximum password lifetime in days (30):
chage -M 30 user01
In both cases, user01 will be presented with a password reset form after authorization (when the time comes):

Configuring SSH access
In most cases, you can already log in to the server as a new user via SSH using a password. But sometimes, for security reasons, login by password is prohibited in the SSH settings, giving preference to keys. It is worth noting that the use of SSH keys itself is more convenient than constantly entering a password. To implement this method of authorization, you just need to copy your public SSH key to the server. Let's consider two ways to do it:1. using ssh-copy-id. The simplest method. It is available when password authorization is enabled in SSH server settings. Use the command:
ssh-copy-id user01@SERVER_IP
- user01 - your user;
- SERVER_IP - IP address of the server.

2. Adding a key manually. The example shows user01, replace it with your own user.
- Create a .ssh directory in the user's home folder:
mkdir /home/user01/.ssh
- Add the public key to the authorized_keys file:
echo "your_public_key" >> /home/user01/.ssh/authorized_keys
- Set permissions on files and directories:
chmod 700 /home/user01/.ssh
chmod 600 /home/user01/.ssh/authorized_keys
chown -R user01:user01 /home/user01/.ssh

Удаление пользователя
You can delete a user using the userdel utility with a simple command:userdel -r user01
- -r - deletes the user's home directory.
We went through creating a user in Ubuntu 24.04, adding the user to groups, password change settings, sudo and SSH access. Using separate accounts will increase the security of your server. Don't forget:
- Update passwords regularly;
- Delete unused users;
- Use SSH keys instead of passwords.
18 Mar 2025, 23:40:55