Users and their Types
(A.) Users and their Types in Linux
(B.) File and Directory Ownership & Permission
User and Group Management
- User and group management in Linux is essential for administering system security, resource allocation, and access control.
(A.) User Management
-
-
For Adding a New User
- To add/create a new user, the useradd command is used.
- Syntax – sudo useradd username (Press Enter)
-
For Setting a Password for a Newly created User
- passwd command is used to set a password for the user.
- Syntax – sudo passwd username (Press Enter)
-
For Viewing User Details
- who command is used to see the currently logged-in users.
- Syntax – $ who (Press Enter)
- To show/list the detailed user account information. The file (/etc/passwd) contains user account information, including usernames, UIDs, home directories, and default shells.
- Syntax –
- $ cat /etc/passwd (Press Enter)
- $ cat /etc/passwd | grep username (Press Enter)
- Syntax –
- who command is used to see the currently logged-in users.
-
For Modifying User Attributes
- The usermod command is used to modify user properties/attributes.
- To change a user’s home directory : sudo usermod -d /new/home username (Press Enter)
- To Lock a User Account : sudo usermod -L username (Press Enter)
-
For Deleting User Record
-
The userdel command is used to remove a user.
-
Syntax – sudo userdel username (Press Enter)
-
-
To remove the user’s home directory –
-
Syntax – sudo userdel -r username (Press Enter)
-
-
-
Switch to Another Users
- Syntax – su username (Press Enter)
-
To Check Current Users
- To identify the Logged-in Users : $ whoiam (Press Enter)
-
To Check User’s Privileges
- To View groups and permissions : $ id username (Press Enter)
-
(B.) Group Management
-
-
For Creating a New Group
- To create a new group the groupadd command is used.
- Syntax – sudo groupadd groupname (Press Enter)
-
For Adding a User to a Group
-
To add a user to a group the usermod command is used.
-
Syntax – sudo usermod -aG groupname username (Press Enter)
-
- The gpasswd command is also used to add a user to a group.
- Syntax – sudo gpasswd -a username groupname (Press Enter)
-
-
For Viewing Group Membership
-
To check the groups a user belongs to, groups command is used.
- Syntax – $ groups username (Press Enter)
-
The groupmod command is used to change/modify the group name.
-
Syntax – $ groupmod -n newgroupname oldgroupname (Press Enter)
-
-
-
For Deleting a Group
- To remove an existing group the groupdel command is used.
- Syntax – sudo groupdel groupname (Press Enter)
-
(C.) User Identification(UID) Management
There are following types of UID in the Linux system –
-
-
User IDs (UIDs):
- Each user is associated with a unique identifier called a User ID (UID).
- The common UID ranges are:-
0
: Root user.1–999
: System and Service Users (may vary by distribution).1000 and above
: Regular users (default range for most Linux distributions).
-
Group IDs (GIDs):
- GIDs are the IDs provided to the Users that can belong to groups to simplify permission management.
-
User and Group Configuration Files
- Linux uses several configuration files to manage users and groups. These files are critical for defining user accounts, group memberships, and their attributes.
- Some common user and group configuration files are –
- /etc/passwd :
- This file contains user account information.
- To view the user information/file contents – $ cat /etc/passwd (Press Enter)
- Each line of output represents single user details and follows this format
- /etc/passwd :
-
-
-
-
-
username
: The login name of the user. -
x
: Placeholder for the encrypted password (stored in/etc/shadow
for security). -
UID
: User ID, a unique numeric identifier for the user. -
GID
: Group ID, referring to the user’s primary group (defined in/etc/group
). -
comment
: Optional user description or full name. -
home_directory
: Path to the user’s home directory. -
shell
: The user’s default shell (e.g.,/bin/bash
).
-
-
-
- /etc/shadow :
-
This file stores secure information about user passwords.
- To show the file contents – $ cat /etc/shadow (Press Enter)
-
Each line of output represents single user details corresponding to a user from /etc/passwd and follows this format –
-
-
username
: The login name of the user.encrypted_password
: Hashed password or special values like:!
or!!
: Account is locked.*
: No password set.
last_changed
: Days since January 1, 1970, when the password was last changed.min_days
: Minimum days between password changes.max_days
: Maximum days before the password expires.warn
: Days before expiration to warn the user.inactive
: Days after expiration before the account is disabled.expire
: Account expiration date in days since January 1, 1970.
-
- /etc/group:
0 Comments