It is one of the most important and interesting topic of the LINUX Operating System because with proper understanding of this topic and file permissions (Explained in our Linux Tutorial Section) only one can become a good System Administrator( I hope you know this).
Now let’s get started.
NOTE Whatever we will do, we will do with the help of command line (Terminal) and not GUI because only terminal can give us a proper understanding of what we are doing and what we are supposed to do.
The very first task is to learn how to add and delete users (with Command Line off course)
To add Linux Users. Only root (who is root?) can execute this command
[[email protected] root]#useradd username
To assign/change password to any user.
Two ways/types of usage:-
This command is executed by super user (root) to change password of any linux user.
[[email protected] root]#passwd username
This command is executed by any particular user to change his own password.
[[email protected] username]#passwd
To delete a user from linux system. Only root can execute this command.
[[email protected] root]#userdel username
To increase the functionality , maintaining flexibility and improving security and privacy concerns we take the help of concepts of group. Every Linux user is essentially part of atleast one group. By default tis group is nothing but same as the name of the user. That means if we create a user named “apple” then this apple user will be part of group “apple” by default which was created by system during execution of command “useradd apple”.
Any user can be added to any group (obviously only root can do that) therefore according to needs and security reasons we can add or remove users from group.
How to Create a Group
To add a group in Linux. Only root can execute the command.
[[email protected] root]#groupadd groupname
To delete a group. Only root can execute.
[[email protected] root]#groupdel groupname
TYPES of GROUPS
1) Primary Group of user- Any user can has exactly one primary group and many users can simultaneously have same group as their primary group.
2) Secondary group of user- User can have any number of secondary groups.
How to Add/ Remove Groups of A User
Used to change the profile of any user.Only root have the privileges to execute the command.
[[email protected] root]#usermod -parameter groupname username
Here parameters (for the time being) take two values g or G.
Usage with small g or g
[[email protected] root]#usermod -g groupname username
Here groupname will be the primary group of the user.
Usage with capital G or G
[[email protected] root]#usermod -G groupname1,groupname2 username
Here secondary group/groups are being added to the user. Every time you execute the command you are supposed to re-enter all the previous secondary groups of the user otherwise they will be removed.
PASSWORD FILE :- I know what is going in your mind after reading the heading of this topic but to your disappointment this is not what you wish to learn. Yes this file does not contain any password.
Password file contains the information of every user of the system except its password. It contains the User ID, Group ID, general user information, paths of home directory and login shell.
Path of password file:- /etc/passwd (Mind the spelling of passwd)
SHADOW FILE :- This file contains the password of users. Yes!! Finally you got something with the help of which you can try to hack into the account of the “dude” you hate most or the prettiest girl of your class. But to your disappointment again this contains password but in encrypted form. Better luck next time. And to increase your misery only root can see the shadow and passwd file.
Path of Shadow file:- /etc/shadow
GROUP FILE: This contains the information of the various groups present in the system and their GroupID and secondary users.
Path of the File:- /etc/group
HOW to know Primary and Secondary groups of a user
to know about groups of any user
[[email protected] root]groups username
It will show the groups of any particular user with first showing primary group and then all the secondary groups.