Add and Manage Users and Groups In Linux Using Command Line

Managing Users and Groups In Linux Using Command Line is a basic task performed by a system admin. Adding new users to system can be done using GUI interfaces also but using command line make it simple and easy. Using command line to manage and add users becomes very handy when we are sitting in front of a linux terminal and the target system is 2000 miles away.

I will start with some basics of user management basically some linux terminology associated with users and groups
UID -> Each user when created is provided a user id. This id is unique.
GID -> As each linux user gets a unique user id every group in linux gets a unique group id.

There are two types of users in linux namely normal users and root.

Files associated with user and group management in Linux.

  • /etc/passwd -> this file stores the loginname, encrypted password,UID, default GID and name. This name field is called GECOS sometimes and generally stores the contact information about the user. The typical output of a /etc/passwd file can be seen asHere is a standard output of as /etc password file

    Add and Manage groups and users in linux using command line 1

    1st entry: user account name
    2nd entry: password
    3rd entry: UID
    4th entry: user’s GID
    5th entry: GECOS or the name or some comments
    6th entry: home directory
    7th column: default shell

    Note: if UIS is less than 99 then those are service accounts in LINUX.

  • /etc/shadow-> In the above screen shot the 2nd column shows garbage values but that is not garbage value it is the encrypted password. The password is stored in encrypted format so as no one can read it. The password is stored in /etc/shadow file.
  • /etc/group-> This files stores the group name, group password ( only if the group is joinable), GID and the group members.

Now as we know the basic we can workaround with adding and managing users.The commands that are important are:

useradd-> add new user account.

usermod->modify the existing user accounts

userdel->delete user accounts.

groupadd->add new user groups.

groupmod->modify existing user groups.

groupdel->delete a user group.

Step1.) Adding new user.

useradd -c “Akash Deep” -s /bin/sh -k /etc/skel -m -d /home/akash akash

This command adds a new user akash

-c to add the name or the GECOS [AKASH DEEP]

-s sets the default shell

-k uses the default template of creating a user stored in /etc/skel

-d specifies the home directory of a user.

The new screenshot is like this

Add and Manage Users and Groups In Linux Using Command Line 2

Step2.) Adding new group.

groupadd -g 520 blogs

This commands adds a new group called blogs

-g specifies the gid which should be equal to or greater than 500.

-r It specifies that the system group is a system group and value is less than 499.

To change users and groups just use commands usermod and groupmod with the same options as specified above.

Akash Deep Singh

|| Eat Packets || Drink Management || Sleep Virtual || Work Linux || Think I.T. || Love MAC || Look After Windows || Dream APPS ||

3 Comments

  1. Burton Hayn   •  

    Nice info here..

  2. cialis   •  

    Ooooo :)

  3. nath   •  

    Keep posting stuff like this i really like it

Leave a Reply

Your email address will not be published. Required fields are marked *