Essential Linux Commands for User and File Management
Day 4: Essential Commands for Linux User and File Management
Linux is a fantastic platform that allows multi-user access options. Different users can access the same Linux OS for working simultaneously. A user account allows multiple people to access directories, terminals, the Internet, etc. There are three types of user accounts:
User Account: This account is for general use with limited permissions.
System Account: This account is used for operating specific programs such as daemon, MySQL, mail, etc.
Root Account: This account is for administrators. It has unlimited access to change the system.
Commands for User Managment :
1. unmask
The unmask command is used to set the default permission for newly created files and directories in Linux. It defines the mask of permissions that will not be set on newly created files.
Usage:
unmask [permissions]
Example: To set the default permission to rw-r--r-- (644)
unmask 022
2. adduser
The adduser command is a script that is typically used to add a new user to the system. It is more user-friendly than useradd.
Usage:
sudo adduser username
Example: To add a new user named Aditya:
sudo adduser Aditya
This command prompts for a password and other user information.
3. set password
To set or change a user's password, you can use the passwd command.
Usage:
sudo passwd username
Example: To set a password for the user Aditya:
sudo passwd Aditya
You will be prompted to enter a new password.
4. addgroup
The addgroup
command is used to create a new group in the system.
Usage:
sudo addgroup groupname
Example: To create a new group named developers:
sudo addgroup developers
5. usermod
The usermod command is used to modify an existing user account.
Usage:
sudo usermod [options] username
Common Options:
-aG group: Add the user to a supplementary group.
-d home: Change the home directory.
-l new_username: Change the username.
Example: To add Aditya to the developers group:
sudo usermod -aG developers Aditya
6. useradd
The useradd command is used to create a new user account. It is a lower-level command compared to adduser.
Usage:
sudo useradd [options] username
Common Options:
-m
: Create a home directory.-s
: Specify the login shell.Example: To add a new user named Aditya with a home directory:
sudo useradd -m Aditya
7. chmod
The chmod command is used to change the permissions of files or directories.
Usage:
chmod [options] mode file
Modes:
Numeric:
777
,755
, etc.Symbolic:
u+x
,g-w
,o=r
, etc.Example: To give the user execute permission on a file named script.sh:
chmod u+x script.sh
Example: To set permission to
755
(rwxr-xr-x) for Adi:chmod 755 Adi
8. man
The man command is used to display the manual pages of commands. It provides documentation about commands, options, and usage.
Usage:
man command
Example: To view the manual page for chmod:
man chmod
Summary of Commands :
Command | Description | Example |
unmask | Set default permission for new files/dirs | unmask 022 |
adduser | Add a new user to the system | sudo adduser john |
passwd | Set or change a user's password | sudo passwd john |
addgroup | Create a new group | sudo addgroup developers |
usermod | Modify an existing user account | sudo usermod -aG developers john |
useradd | Create a new user account | sudo useradd -m alice |
chmod | Change file or directory permissions | chmod u+x script.sh |
ps | Display information about running processes | ps -e |
man | Display the manual page for a command | man chmod |
These commands are essential for user and file management in Linux systems.
Conclusion :
In Linux, a robust set of commands facilitates efficient system administration and user management. Understanding commands like unmask
, adduser
, passwd
, addgroup
, usermod
, useradd
, chmod
, ps
, and man
is crucial for any user or administrator aiming to navigate the system effectively.