Users in Linux are accounts that identify who is using the system and control access to files, processes, and resources. Each user is associated with unique identifiers:
- UID (User ID): A number assigned to identify the user.
- GID (Group ID): The primary group the user belongs to.
- Home Directory: A private space for the user.
- Shell: The command-line interface for the user.
graph TD
A[Linux System]
A --> B[Root User]
A --> C[System Users]
A --> D[Regular Users]
C --> E[postgres]
D --> F[boris]
D --> G[testuser]
List all users on the system:
cat /etc/passwd
- Each line represents a user account in the format:
username:x:UID:GID:comment:home_directory:shell
Create a user with a home directory and prompt for a password:
sudo adduser testuser
testuser
: The name of the new user.- Prompts for a password and creates
/home/testuser
.
Assign a new password to a user:
sudo passwd testuser
- Prompts for a new password.
- Updates the password for
testuser
.
Change to a different user account:
su - testuser
-
: Loads the new user’s environment (e.g.,.bashrc
).- Prompts for the user’s password.
Remove a user account:
sudo deluser testuser
--remove-home
: Also deletes the user’s home directory.
Check details for a specific user:
grep testuser /etc/passwd
- Displays the account’s configuration.
Ensure a user is not locked:
sudo passwd -u testuser
- Unlocks the account if it was locked.
View file ownership and permissions:
ls -l
- Example output:
-rw-r--r-- 1 boris boris 1024 Dec 20 file.txt
- Owner:
boris
- Group:
boris
- Owner:
Change file ownership:
sudo chown testuser file.txt
- Assigns ownership to
testuser
.
- Use separate users for different roles (e.g., database administration).
- Avoid running processes as
root
unless necessary. - Regularly audit user accounts to ensure proper permissions.
- Test configurations or scripts with isolated test users.