Support Online
Skip to main content

Guide to Adding, Deleting and Authorizing Users in Ubuntu 24.04

💡 What Will You Learn in This Guide?

You will learn to create and manage new user accounts to increase security in the Ubuntu 24.04 operating system.
You will understand the importance of using unprivileged users instead of a root account, and you will apply two different ways to grant administrative authority (sudo) to users.
You'll also learn how to delete or temporarily lock users who are no longer needed.

🔧 Prerequisites

  • A server with Ubuntu 24.04 installed
  • A user account with root access or sudo authority
  • Firewall (UFW) must be enabled

If you don't have a server yet, you can create an Ubuntu 24.04 server in a few clicks via the GenixNode Platform.


🧍‍♂️ 1. Adding a New User

After setting up a server, the safest approach is to create an unprivileged user instead of a Root account.

🔹 Adding as root

adduser yenikullanici

This command creates the new user and installs the necessary directories.

🔹 Adding with sudo authorized user


sudo adduser yenikullanici

If you are logged in as a user with sudo privilege, use this command.

🔸 Process Steps

Set Password: Create a strong password for the new user.

Additional Information: Name, phone number, etc. You can fill in additional information or leave it blank.

Confirmation: Press Y to confirm the information.

Your new user account is now active!


🔐 2. Granting Sudo Privileges to the User

You must grant sudo access for the new user to be able to run commands with administrative authority. There are two methods:

In Ubuntu, users added to the sudo group automatically have administrator rights.


sudo usermod -aG sudo yenikullanici

The -aG parameter includes the user in the sudo group in addition to their existing group.

To check the user's groups:


groups yenikullanici

If you see newuser: newuser sudo in the output, the process is complete.

🅱️ Method B – Define explicit permissions in /etc/sudoers file

This method gives full authority directly to the user.


sudo visudo

Find the following line in the file:


root ALL=(ALL:ALL) ALL

Add the following line for the new user underneath:


yenikullanici ALL=(ALL:ALL) ALL

Press Ctrl + X, then Y and Enter to save.

✅ Authority Test

After logging in with the new user:


sudo apt update

run command. If a password is requested and the process is completed successfully, sudo authority is active. 🎯


❌ 3. User Deletion and Locking

🔹 Deleting User

Deleting by Keeping Files

sudo deluser silinecek_kullanici

This command deletes the user account but preserves the home directory.

Deleting Home Directory by Deleting it

sudo deluser --remove-home silinecek_kullanici

It completely removes the user's account and home directory.

🔹 Temporarily Locking User

Sometimes it may be necessary to temporarily disable the user rather than completely deleting them.

Lock Password


sudo passwd -l kilitlenecek_kullanici

It invalidates the user's password and cannot log in.

Unlock


sudo passwd -u kilitlenecek_kullanici

Reactivates the user's login.

Disable Session Shell


sudo usermod -s /usr/sbin/nologin kilitlenecek_kullanici

Prevents the user from logging into the terminal.

If you want to enable it again:


sudo usermod -s /bin/bash kilitlenecek_kullanici

⚙️ User Management Command Summary

TaskCommandDescription
Add usersudo adduser aliCreates a new user.
Add to sudo groupsudo usermod -aG sudo aliGives administrator authority.
Delete usersudo deluser aliRemoves the user from the system.
Deleting with home directorysudo deluser --remove-home aliIt deletes it along with all its files.
Locking passwordsudo passwd -l aliIt prevents him from logging in.
Password unlocksudo passwd -u aliReactivates the account.
Closing the login shellsudo usermod -s /usr/sbin/nologin aliTurns off shell access.

❓ Frequently Asked Questions (FAQ)

1. What is the difference between adduser and useradd?

adduser is an interactive and user-friendly script. It automatically handles home directory, skeleton files and password operations. useradd is a lower level command and requires manual parameters.

2. How do I remove sudo privilege from a user?

bash

sudo deluser to be removed_user sudo This command removes the user from the sudo group. If you added a line manually to /etc/sudoers, open the file with sudo visudo and delete the relevant line.

3. Can I back up the home directory when deleting a user?

Yes.

bash

sudo deluser --backup-home will be deleted_user The command creates a .tar.gz backup under /var/backups/ before deleting the home directory.

4. Is it possible to bring back a user after deleting them?

There's no "remove" exactly, but if --remove-home is not used, the home directory will remain. You can recreate the account and access your files using the same username and UID.

5. Which method is safer — deleting users or locking them?

Completely deleting the user is permanent, but locking them temporarily blocks access. For critical accounts, locking (passwd -l) may be a safer choice.


🌟 Result

Effective user management is the foundation of security on Ubuntu 24.04 servers. By using the adduser, usermod, deluser and passwd commands correctly, you can keep your system both organized and secure.

Take your system administration skills to the next level by trying these steps on GenixNode Servers now! 🚀