Searching...

Adding and removing users in Linux

After installing a Linux operating system (Ubuntu, Debian, Arch Linux...), often only the root user or a user with SUDO privileges is available. Using the root user gives you a lot of power over the system, but it can also potentially lead to the complete destruction of the system. Therefore, it's better to create a new regular user for typical tasks, or even multiple users if your machine is used by multiple people, and configure permissions for users regarding what they can and cannot do with the system.

Creating a New User

If you're using the root user, you can create a new user with the following command:

adduser

Alternatively, if you're not using the root user but a user with sudo privileges, you can add a user with:

sudo adduser

Let's create a user named "mike."

sudo adduser mike

This will prompt you to:

  • Set and confirm the password,
  • Provide optional information, which you can skip by pressing Enter,
  • Confirm all the information, where you can simply type "Y" and press Enter.

Granting SUDO Permissions to a User

If the new user should have the ability to execute commands with administrative privileges, you'll need to grant the user access to sudo.

You can add the new user to the sudo group:

usermod -a -G sudo mike

Now, the user "mike" can use sudo.

Removing a User

When you no longer need a particular user, you can remove them.

To remove a user without deleting any of their files or directories, use:

sudo deluser mike

If you want to remove their home directory as well, you can use:

sudo deluser --remove-home mike

Once you have created the user, you can try changing file permissions with the new user. Instructions on how to do this can be found here.

Done.

Comments

To submit comment you have to be logged-in