User Management and Permissions in Linux
User management and permissions are crucial components of Linux, especially for hackers and cybersecurity professionals. Managing users effectively and understanding file permissions ensures secure and controlled access to system resources. In this article, we’ll cover the fundamentals of Linux user management and file permissions to help you get started.
User Management in Linux
Linux is a multi-user operating system, meaning multiple users can operate on the same system simultaneously. Each user has specific permissions and access levels defined by the system.
1. Adding Users
- Command:
adduser
- Adds a new user to the system.
- Example:
sudo adduser hacker
creates a user namedhacker
.
- Command:
useradd
- An alternative to
adduser
with fewer defaults. - Example:
sudo useradd -m hacker
creates a user and their home directory.
- An alternative to
2. Deleting Users
- Command:
deluser
- Removes a user from the system.
- Example:
sudo deluser hacker
- Command:
userdel
- Similar to
deluser
but more basic. - Example:
sudo userdel -r hacker
deletes the user and their home directory.
- Similar to
3. Modifying Users
- Command:
usermod
- Modifies user settings, such as group memberships and home directories.
- Example:
sudo usermod -aG sudo hacker
adds the userhacker
to thesudo
group.
4. Viewing User Information
- Command:
id
- Displays user ID (UID) and group ID (GID) information.
- Example:
id hacker
- Command:
who
- Shows who is currently logged into the system.
- Example:
who
- Command:
finger
- Displays user information, such as login times and home directories (requires installation).
- Example:
finger hacker
5. Managing Groups
- Groups allow you to organize users and set collective permissions.
- Commands:
groupadd
: Adds a new group.- Example:
sudo groupadd developers
- Example:
gpasswd
: Adds users to a group.- Example:
sudo gpasswd -a hacker developers
- Example:
groupdel
: Deletes a group.- Example:
sudo groupdel developers
- Example:
File Permissions in Linux
Permissions in Linux determine who can read, write, or execute files and directories. These permissions are assigned to three categories:
- Owner: The user who owns the file.
- Group: A group of users with shared access.
- Others: All other users.
Viewing File Permissions
- Command:
ls -l
- Displays detailed file information, including permissions.
- Example:
-rw-r--r-- 1 hacker developers 1024 Jan 28 10:00 example.txt
-rw-r--r--
: File permissions.hacker
: File owner.developers
: File group.
Understanding Permission Codes
Each file has three permission sets: owner, group, and others.
- Read (r): View the file or directory contents.
- Write (w): Modify the file or directory.
- Execute (x): Run the file as a program.
- Example:
rw-
: Read and write permissions.r--
: Read-only permission.
Modifying Permissions
- Command:
chmod
- Changes file permissions.
- Example:
chmod 755 script.sh
- assigns full permissions to the owner and read/execute permissions to others.
Changing Ownership
- Command:
chown
- Changes file owner and group.
- Example:
sudo chown hacker:developers example.txt
Practical Examples
- Creating a New User and Assigning Permissions:
- Add a user:
sudo adduser pentester
- Assign to a group:
sudo usermod -aG sudo pentester
- Create a secure directory for the user:
mkdir /home/pentester/secure
- Set permissions:
chmod 700 /home/pentester/secure
- Add a user:
- Collaborative Projects:
- Create a shared group:
sudo groupadd project
- Add users to the group:
sudo gpasswd -a hacker project
- Set group ownership of a directory:
sudo chown :project /home/project
- Assign group permissions:
chmod 770 /home/project
- Create a shared group:
Why User Management and Permissions Matter
- Security: Proper permissions prevent unauthorized access to sensitive data.
- Collaboration: Groups and permissions simplify managing shared resources.
- System Stability: User isolation reduces the risk of accidental damage.
If you’ve found this article helpful and enjoy learning about Linux and Ethical Hacking, consider supporting my work! Your contribution helps me create more free, high-quality content for the community and keeps the site ad-free. Every bit of support allows me to continue sharing knowledge and exploring the ever-evolving world of technology. If you’d like to support, you can Buy me a coffee. Thank you for your kindness and generosity!