Linux User Management & Permissions
Understanding users, groups, and file permissions for beginners
Linux is a multi-user system where files and directories have permissions that control who can read, write, or execute them. Understanding these concepts is essential for system administration and security. Permissions are represented in two ways: symbolic notation (rwx) and numeric notation (like 755 or 777).
Understanding rwx Permissions
Permissions are divided into three categories, each represented by three characters:
Read (r)
Permission to view or copy file contents. For directories, allows listing contents.
Write (w)
Permission to modify or delete files. For directories, allows creating/removing files.
Execute (x)
Permission to run a file as a program. For directories, allows entering (cd) into it.
Permission Groups
Each file has three sets of permissions for three different groups:
How Numeric Permissions Work (755, 777, etc.)
Numeric permissions use octal (base-8) representation where each digit represents one permission group (Owner, Group, Others). Each digit is the sum of read (4), write (2), and execute (1) permissions:
Common for executable files and scripts.
Standard for regular files (config files, documents).
Full access for everyone. ⚠️ Avoid on production - security risk!
Owner only, private files (like SSH keys, passwords).
Common Commands
$ chmod 755 script.sh # Set permissions to rwxr-xr-x
$ chmod +x script.sh # Add execute permission for all
$ chmod u+w file.txt # Add write for owner only
$ chmod g-r file.txt # Remove read for group
$ chmod 644 file.txt # Set to rw-r--r--
$ chown user:group file.txt # Change owner and group
$ chown user file.txt # Change owner only
$ sudo chown -R www-data:www-data /var/www # Recursive ownership
$ groups # Show your groups
$ id # Show user ID and groups
$ whoami # Show current username
User Management Basics
Creating Users
$ sudo adduser newuser # Interactive user creation
$ sudo useradd -m -s /bin/bash newuser # Non-interactive
Managing Groups
$ sudo groupadd developers # Create group
$ sudo usermod -aG sudo user # Add user to sudo group
$ sudo usermod -aG docker user # Add user to docker group
$ sudo deluser user # Delete user
Checking Permissions
$ ls -l file.txt # Show permissions
$ ls -la # Show all files with permissions
$ stat file.txt # Detailed file info
Security Tips
- Never use 777 permissions - it gives everyone full access
- Use 755 for directories, 644 for regular files
- Keep sensitive files (like private keys) at 600
- Web server files should typically be owned by the web server user (e.g., www-data)
- Use groups to share access between users rather than opening permissions to everyone