How To Add/Remove New User In Linux/Unix

How To Add/Remove New User In Linux/Unix

 

This post was last updated on August 3rd, 2020 at 03:09 pm

In this article, we will learn to add or remove users and giving them required permissions in Linux or Unix. As these operating systems are multi-user many users can have accounts on a single OS and can use resources simultaneously at a time. So It is necessary to manage all the users or user groups. A system administrator manages all these user or user groups and their rights. We will use the command-line user interface to create, delete, and grant the root privileges to the created user.

Creating a new user

If currently you are logged in as root user or have superuser privileges. You can directly execute the command given below in your terminal

$ adduser new_user_name

Otherwise, if you do not have root access you can use the command below

$ sudo adduser new_user_name

It will ask to enter the new Unix password for the newuser, enter it. And again retype when it asks. Then it will ask other details about the user which are optional you can skip by hitting enter. Finally, confirm that the information provided is correct. Press y and then enter. Now a newuser has been created.

Grant sudo privileges to the new user

Sometimes we need to execute commands which require root access like installing or removing a package. By default created users will not have that access. So we will have to provide superuser privileges to the new user for that we will add created user to the sudo group. When we create a new user it automatically gets added to its own group. To check the group of a user we should use groups command as given below-

$ groups new_user

To get all groups in the system use the following command in your terminal.

$ getent group | cut -d: -f1

We will now add the created user to the sudo group. To add a new user into a group we should use usermod command. Syntax of which is given below:

$ usermod -aG group_name user_name

here we will add a new user with name newuser to the sudo group. Note that the newuser is now added in two groups that are newuser its own group and sudo.

 

Deleting user

If you no longer need that user account you can delete it by using the following command

$ sudo deluser newuser

It will not delete user data you can delete it later by using the following command

$ sudo deluser --remove-home newuser

Now I think you should have a basic understanding of creation, removal of the user, and adding that user into a group. If you have any query write to us in the comments below.

Previous File Ownership And Permissions In Linux/Unix
Next How To Write And Execute A Shell Script In Linux/Unix
 

About author

You might also like

Linux Topics 0 Comments

How To Set Read/Write Permissions On A NTFS Partition In Linux?

This post was last updated on September 1st, 2020 at 03:36 pmA hard disk can have various partitions on it. Partition refers to the logical divisions of a physical disk

How To 0 Comments

How To Resize The “/” (root) Partition In Linux?

This post was last updated on August 1st, 2020 at 12:52 pmA partition is nothing but a logical division of a physical disk. Partition makes it easy to organize and

Linux Topics 0 Comments

How To Install a Package From .tar.gz Or .tar.bz2 File In Linux?

This post was last updated on August 1st, 2020 at 02:17 pmA file archiver is used to hold multiple files into a single archive file. And a file compression utility

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply