Creating a user with a default setting: A user can be added by running the useradd command at the command prompt.
# useraddabc
# passwdabc
Changing password for user anirban.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
Specifying a user’s full name when creating a user: A systems administrator can use the –c option with useradd to specify the user’s full name, as shown below:
# useradd -c “Anil Bhai Choudhury” abc
Creating a user with the UID: You can create a user with a custom UID with the –u option, as follows:
# useradd -u 1036 abc
Adding a user to a primary group and supplementary group: A systems administrator can specify a primary group and a supplementary one by specifying the –g and –G option, respectively.
# useradd -g “head” -G “faculty” abc
Locking and unlocking a user: A super user can lock and unlock a user account. To lock an account, one needs to invoke passwd with the -l option.
# passwd -l abc
Locking password for user abc.
passwd: Success
The –u option with passwd unlock an account
# passwd -uabc
Unlocking password for user abc.
passwd: Success
Changing a user name: The –l option with the usermod command changes the login (user) name, as shown below:
# usermod -l “pqr” abc
Removing a user: Combining userdel with the –r option drop a user and the home directory associated with that user, as shown below:
# userdel -r pqr
Linux group
Linux group is a mechanism to organise a collection of users. Like the user
ID, each group is also associated with a unique ID called the GID (group ID).
Creating a group with default settings: To add a new group with default settings, run the groupadd command as a root user, as shown below:
# groupaddmygroup
Changing the group’s name: To change the group’s name, run the groupmod command with the -n option as a super user, as shown below:
# groupmod -n mynewgroupmygroup
Creating a group with a specified GID: To explicitly specify the GID of a group, execute the groupadd command with the –g option, as follow:
# groupadd -g 1200 manager
Deleting a group: Before deleting a primary group, delete the users of that primary group. To delete a group, run the groupdel command with the group name, as shown below:
# groupdelmynewgroup