Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Add and Delete Users in Ubuntu 22.04

    How to Add and Delete Users in Ubuntu 22.04

    By RahulDecember 28, 20224 Mins Read

    Ubuntu is a popular open-source operating system based on the Linux kernel. It is widely used on personal computers, servers, and in cloud computing environments. One of the key tasks in managing a Ubuntu system is managing users and groups. In this article, we will explain how to add and delete users in Ubuntu 22.04.

    Advertisement

    Before we begin, it is important to note that in Ubuntu, only users with administrative privileges (also known as “root” users) can add and delete other users. If you do not have administrative privileges, you will need to ask an administrator to perform these tasks for you.

    Adding Users in Ubuntu

    The `adduser` command in Linux is used to create a new user in the system. It is typically used with the following syntax:

    1
    2
    <comment>## Syntax </comment>
    adduser [options] username

    Some common options that can be used with the `user_name` command are:

      • -c: Specifies the user’s full name.
      • -d: Specifies the user’s home directory.
      • -g: Specifies the user’s primary group.
      • -G: Specifies a list of secondary groups that the user belongs to.
      • -m: Creates the user’s home directory if it does not already exist.
      • -s: Specifies the user’s login shell.
      • -u: Specifies the user’s UID (user ID).

    To add a new user in Ubuntu, follow these steps:

    1. Open a terminal window by pressing `Ctrl + Alt + T` or by searching for “Terminal” in the dashboard.
    2. Type the following command to add a new user, replacing the `user_name` with the desired username:
      sudo adduser user_name 
      
    3. You will be prompted to enter a password for the new user. Enter a strong password and confirm it by retyping it.
    4. You will also be prompted to enter various personal information for the new user, such as the user’s name, phone number, and email address. You can leave these fields blank by pressing “Enter” if you do not want to provide this information.
    5. Once the user has been created, you can set additional user privileges using the `usermod` command. For example, to add the user to the `sudo` group, which allows the user to perform administrative tasks, use the following command:
      sudo usermod -aG sudo user_name 
      
    6. You have successfully added a new user account in the Ubuntu system. See the below screenshot for the expected command output:
    Create a New User in Ubuntu
    Create a New User in Ubuntu

    Let’s see another example with a few options, to create a new user with the username “tecadmin” , a home directory at “/var/home/tecadmin” , and the Zsh shell as the login shell, you could use the following command:

    adduser -m -d /var/home/tecadmin -s /bin/zsh tecadmin 
    

    For a complete list of options and more information about the adduser command, you can consult the adduser man page by typing `man adduser` in a terminal window.

    Deleting Users in Ubuntu

    To delete a user in Ubuntu, follow these steps:

    1. Open a terminal window as described above.
    2. Type the following command to delete the user, replacing `user_name` with the username of the user you want to delete:
      sudo deluser user_name 
      
    3. You will be prompted to confirm the deletion. Type `Y` and press Enter to proceed with the deletion.
    4. If the user you are deleting has files in their home directory, you will be asked if you want to remove these files as well. If you want to delete the user’s files, type `Y` and press `Enter`. If you do not want to delete the user’s files, type N and press Enter.
    Delete User in Ubuntu
    Delete User in Ubuntu

    Note: It is generally a good idea to back up any important files before deleting a user. Once a user and their files are deleted, they cannot be recovered.

    Conclusion

    In this article, we have explained how to add and delete users in Ubuntu 22.04. We have also discussed how to set additional user privileges using the usermod command and how to delete a user’s files during the deletion process. With these skills, you should now be able to manage users and groups on your Ubuntu system effectively.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9

    How to Install MySQL 8.0 on RHEL & CentOS Stream 9

    How to Split Large Archives in Linux using the Command Line

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • What is the /etc/mtab File in Linux
    • The “Hello World” Challenge: Printing in 20 Different Programming Languages
    • How to Install PHP 8.2-7.4 on RHEL & CentOS Stream 9
    • How to Install MySQL 8.0 on RHEL & CentOS Stream 9
    • How to Split Large Archives in Linux using the Command Line
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.