Linux CLI 18 🐧 id, chmod and umask commands
These three commands handle user identity, file permissions, and default permission rules. Together, they form the foundation of Linux access control.
Overview
| Command | Purpose | Best For |
|---|---|---|
id | Show user identity | Finding your UID, GID, and groups |
chmod | Change permissions | Setting who can read/write/execute |
umask | Set default permissions | Controlling defaults for new files |
The id Command
Displays information about a user — their identity and group memberships.
id
id kronos
id -u kronos
id -g kronos
id -n kronos
id -G kronos
| Command | Description |
|---|---|
id | Info for the current user |
id kronos | Info for a specific user |
id -u kronos | Show the user ID (UID) |
id -g kronos | Show the primary group ID (GID) |
id -n kronos | Show the name instead of numeric ID |
id -G kronos | Show all groups the user belongs to |
Examples
Current user info:
$ id
uid=1000(kronos) gid=1000(users) groups=1000(users),4(adm),27(sudo),1001(developers)
Specific user:
$ id kronos
uid=1000(kronos) gid=1000(users) groups=1000(users),4(adm),27(sudo),1001(developers)
User ID only:
$ id -u kronos
1000
Group ID only:
$ id -g kronos
1000
Group name instead of number:
$ id -n -g kronos
users
All groups (numeric):
$ id -G kronos
1000 4 27 1001
All groups (names):
$ id -Gn kronos
users adm sudo developers
Understanding id Output
uid=1000(kronos) gid=1000(users) groups=1000(users),4(adm),27(sudo),1001(developers)
│ │ │ │ │ │ │ │
│ │ │ │ │ │ │ └── Additional group
│ │ │ │ │ │ └────────── Additional group
│ │ │ │ │ └───────────────── Additional group
│ │ │ │ └──────────────────────────── Primary group name
│ │ │ └────────────────────────────── Primary group ID
│ │ └──────────────────────────────────────────── Username
│ └────────────────────────────────────────────── User ID
└───────────────────────────────────────────────────────────── Identifier type
Key concepts:
| Term | Meaning |
|---|---|
| UID | User ID — a number that identifies a user |
| GID | Group ID — a number that identifies a group |
| Primary group | The main group a user belongs to |
| Supplementary groups | Additional groups a user belongs to |
Root User
$ sudo id
uid=0(root) gid=0(root) groups=0(root)
# UID 0 = root (superuser)
Common UIDs:
| UID | User | Notes |
|---|---|---|
| 0 | root | Superuser |
| 1–999 | System users | Services, daemons |
| 1000+ | Regular users | Human users |
The chmod Command
CHange MODe — changes permissions of a file or directory.
chmod u+rwx,g-wx,o=rx 1.txt
chmod 640 1.txt
Who can use it?
- The owner of the file
- The superuser (root)
Two Ways to Change Permissions
| Method | Example | Style |
|---|---|---|
| Symbolic | chmod u+rwx,g-wx,o=rx file | More readable |
| Octal | chmod 640 file | More concise |
Method 1: Symbolic Representation
| Symbol | Meaning |
|---|---|
u | User (owner) |
g | Group |
o | Others |
a | All (u+g+o) |
+ | Add permission |
- | Remove permission |
= | Set exact permissions |
r | Readable |
w | Writable |
x | Executable |
s | Set user ID |
S | Set group ID |
Symbolic Examples
# Add read, write, execute to the owner
chmod u+rwx file.txt
# Remove write and execute from the group
chmod g-wx file.txt
# Set exact permissions for others (read + execute)
chmod o=rx file.txt
# Combine multiple changes
chmod u+rwx,g-wx,o=rx file.txt
# Add execute to everyone
chmod a+x script.sh
# Same as: chmod u+x,g+x,o+x script.sh
# Remove write from group and others
chmod go-w file.txt
# Set specific permissions for owner only
chmod u=rw file.txt
Step-by-Step: chmod u+rwx,g-wx,o=rx 1.txt
Starting state (assume 1.txt has rw-rw-rw-):
| Change | Result |
|---|---|
| Start | rw-rw-rw- |
u+rwx — owner gets read+write+execute | rwxrw-rw- |
g-wx — group loses write+execute | rwxr--rw- |
o=rx — others set to read+execute | rwxr-xr-x |
Final: rwxr-xr-x (755)
Method 2: Octal Representation
Three digits, one per group:
640
│││
││└── Others (o)
│└─── Group (g)
└──── Owner (u)
| Octal | Binary | Symbolic | Meaning |
|---|---|---|---|
0 | 000 | --- | No permissions |
1 | 001 | --x | Execute only |
2 | 010 | -w- | Write only |
3 | 011 | -wx | Write + execute |
4 | 100 | r-- | Read only |
5 | 101 | r-x | Read + execute |
6 | 110 | rw- | Read + write |
7 | 111 | rwx | Read + write + execute |
Octal Examples
# Owner: read+write, group: read, others: none
chmod 640 file.txt
# Result: -rw-r-----
# Owner: read+write+execute, group: read+execute, others: read+execute
chmod 755 script.sh
# Result: -rwxr-xr-x
# Owner: read only, group: read, others: read
chmod 444 file.txt
# Result: -r--r--r--
# Owner: read+write+execute, everyone else: nothing
chmod 700 private/
# Result: drwx------
# Owner: read+write, group: read+write, others: read
chmod 664 shared.txt
# Result: -rw-rw-r--
Step-by-Step: chmod 640 1.txt
6 4 0
│ │ │
│ │ └── Others: 0 = --- (no access)
│ └─────── Group: 4 = r-- (read only)
└──────────── Owner: 6 = rw- (read + write)
Result: rw-r----- (640)
chmod Common Patterns
| Octal | Symbolic | Use Case |
|---|---|---|
644 | rw-r--r-- | Regular files |
755 | rwxr-xr-x | Directories, executables |
600 | rw------- | Private files (SSH keys) |
640 | rw-r----- | Shared within group |
664 | rw-rw-r-- | Group-writable files |
700 | rwx------ | Private directories |
777 | rwxrwxrwx | ❌ Avoid (insecure) |
Recursive chmod
# Apply to all files and directories in a tree
chmod -R 755 project/
# Apply only to directories
find project/ -type d -exec chmod 755 {} \;
# Apply only to files
find project/ -type f -exec chmod 644 {} \;
The umask Command
User MASK — determines the default permissions applied to new files and directories.
umask
umask 0000
umask
umask 0022
| Command | Description |
|---|---|
umask | Show current mask |
umask 0000 | Set no restrictions |
umask 0022 | Set common default |
How umask Works
The mask is subtracted from default permissions:
| Type | Base Permission | Subtract umask | Result |
|---|---|---|---|
| Files | 666 (rw-rw-rw-) | 022 | 644 (rw-r--r--) |
| Directories | 777 (rwxrwxrwx) | 022 | 755 (rwxr-xr-x) |
Why base values?
- Files start at 666 — no execute by default (files aren’t programs)
- Directories start at 777 — need execute to enter
Examples
Show current mask:
$ umask
0022
Set umask to 0000:
$ umask 0000
$ umask
0000
# Now new files get: 666 - 000 = 666 (rw-rw-rw-)
# New directories: 777 - 000 = 777 (rwxrwxrwx)
Set umask back to 0022:
$ umask 0022
$ umask
0022
# New files get: 666 - 022 = 644 (rw-r--r--)
# New directories: 777 - 022 = 755 (rwxr-xr-x)
Common umask Values
| Umask | Files | Directories | Use Case |
|---|---|---|---|
022 | 644 | 755 | Default — owner writes, others read |
002 | 664 | 775 | Group collaboration |
077 | 600 | 700 | Private — no group/other access |
027 | 640 | 750 | Group read, no other access |
000 | 666 | 777 | ❌ Insecure — avoid |
Making umask Permanent
Add to ~/.bashrc:
echo "umask 0022" >> ~/.bashrc
Or edit manually:
nano ~/.bashrc
# Add at the end:
umask 0022
# Save: Ctrl+X, then Y, then Enter
source ~/.bashrc
Verify:
$ umask
0022
Testing umask
# Set mask
$ umask 077
# Create a file
$ touch test.txt
$ ls -l test.txt
-rw------- 1 kronos users 0 Jan 15 10:30 test.txt
# Result: 600
# Create a directory
$ mkdir testdir
$ ls -ld testdir
drwx------ 2 kronos users 4096 Jan 15 10:30 testdir
# Result: 700
# Reset
$ umask 022
Complete Example Session
# ============================================
# PART 1: ID COMMAND
# ============================================
# Current user
$ id
uid=1000(kronos) gid=1000(users) groups=1000(users),4(adm),27(sudo)
# Specific user
$ id kronos
uid=1000(kronos) gid=1000(users) groups=1000(users),4(adm),27(sudo)
# UID only
$ id -u kronos
1000
# GID only
$ id -g kronos
1000
# Group name
$ id -gn kronos
users
# All groups (names)
$ id -Gn kronos
users adm sudo
# All groups (IDs)
$ id -G kronos
1000 4 27
# Root user
$ sudo id
uid=0(root) gid=0(root) groups=0(root)
# ============================================
# PART 2: CHMOD — SYMBOLIC
# ============================================
# Starting state
$ ls -l 1.txt
-rw-rw-rw- 1 kronos users 1024 Jan 15 10:30 1.txt
# Add execute to owner
$ chmod u+x 1.txt
$ ls -l 1.txt
-rwxrw-rw- 1 kronos users 1024 Jan 15 10:30 1.txt
# Remove write from group
$ chmod g-w 1.txt
$ ls -l 1.txt
-rwxr--rw- 1 kronos users 1024 Jan 15 10:30 1.txt
# Set others to read+execute
$ chmod o=rx 1.txt
$ ls -l 1.txt
-rwxr--r-x 1 kronos users 1024 Jan 15 10:30 1.txt
# Combined command (from rw-rw-rw-)
$ chmod u+rwx,g-wx,o=rx 1.txt
$ ls -l 1.txt
-rwxr-xr-x 1 kronos users 1024 Jan 15 10:30 1.txt
# ============================================
# PART 3: CHMOD — OCTAL
# ============================================
# Set permissions to 640
$ chmod 640 1.txt
$ ls -l 1.txt
-rw-r----- 1 kronos users 1024 Jan 15 10:30 1.txt
# Set to 755 (common)
$ chmod 755 1.txt
$ ls -l 1.txt
-rwxr-xr-x 1 kronos users 1024 Jan 15 10:30 1.txt
# Set to 644 (default for files)
$ chmod 644 1.txt
$ ls -l 1.txt
-rw-r--r-- 1 kronos users 1024 Jan 15 10:30 1.txt
# Set to 600 (private)
$ chmod 600 1.txt
$ ls -l 1.txt
-rw------- 1 kronos users 1024 Jan 15 10:30 1.txt
# Recursive
$ chmod -R 755 project/
# ============================================
# PART 4: UMASK
# ============================================
# Show current mask
$ umask
0022
# Set to 0000
$ umask 0000
$ umask
0000
# Create a file — see result
$ touch test.txt
$ ls -l test.txt
-rw-rw-rw- 1 kronos users 0 Jan 15 10:30 test.txt
# 666 - 000 = 666
# Create a directory — see result
$ mkdir testdir
$ ls -ld testdir
drwxrwxrwx 2 kronos users 4096 Jan 15 10:30 testdir
# 777 - 000 = 777
# Set to 0077 (private)
$ umask 0077
# Create a file
$ touch private.txt
$ ls -l private.txt
-rw------- 1 kronos users 0 Jan 15 10:30 private.txt
# 666 - 077 = 600
# Create a directory
$ mkdir privatedir
$ ls -ld privatedir
drwx------ 2 kronos users 4096 Jan 15 10:30 privatedir
# 777 - 077 = 700
# Reset to default
$ umask 0022
$ umask
0022
# Make permanent
$ echo "umask 0022" >> ~/.bashrc
$ source ~/.bashrc
# ============================================
# PART 5: PRACTICAL SCENARIOS
# ============================================
# Scenario 1: Setup a web directory
$ mkdir website
$ chmod 755 website
$ cd website
$ touch index.html
$ chmod 644 index.html
# Scenario 2: Protect a private key
$ chmod 600 ~/.ssh/id_rsa
$ ls -l ~/.ssh/id_rsa
-rw------- 1 kronos users 1675 Jan 15 10:30 id_rsa
# SSH requires this permission!
# Scenario 3: Share a file with your group
$ chmod 640 shared.txt
$ ls -l shared.txt
-rw-r----- 1 kronos users 1024 Jan 15 10:30 shared.txt
# Owner can read+write, group can read
# Scenario 4: Group collaboration
$ umask 002
$ touch team.txt
$ ls -l team.txt
-rw-rw-r-- 1 kronos users 0 Jan 15 10:30 team.txt
# Both owner and group can write
# Scenario 5: Set restrictive default for new files
$ umask 0077
$ touch secret.txt
$ ls -l secret.txt
-rw------- 1 kronos users 0 Jan 15 10:30 secret.txt
# Only owner can access
Quick Reference
id Options
| Option | Description |
|---|---|
-u | User ID |
-g | Primary group ID |
-G | All group IDs |
-n | Show names instead of numbers |
-r | Show real ID (vs effective) |
chmod Symbolic
| Symbol | Meaning |
|---|---|
u | Owner (user) |
g | Group |
o | Others |
a | All |
+ | Add |
- | Remove |
= | Set exactly |
r | Read |
w | Write |
x | Execute |
chmod Octal
| Octal | Symbolic | Meaning |
|---|---|---|
0 | --- | None |
1 | --x | Execute |
2 | -w- | Write |
3 | -wx | Write + execute |
4 | r-- | Read |
5 | r-x | Read + execute |
6 | rw- | Read + write |
7 | rwx | Full |
umask Common Values
| Umask | Files | Dirs | Use Case |
|---|---|---|---|
022 | 644 | 755 | Default |
002 | 664 | 775 | Group collaboration |
077 | 600 | 700 | Private |
027 | 640 | 750 | Semi-private |
Best Practices
✅ Do This:
# Files — 644
chmod 644 file.txt
# Directories — 755
chmod 755 mydir
# Private files — 600
chmod 600 ~/.ssh/id_rsa
chmod 600 .env
# Executables — 755
chmod 755 script.sh
# Private directory — 700
chmod 700 ~/.ssh
# Group share — 640 or 664
chmod 640 shared.txt
# Set umask in ~/.bashrc for consistency
echo "umask 022" >> ~/.bashrc
# Verify with id
id
id -Gn
❌ Don’t Do This:
# Don't use 777
chmod 777 file.txt # ❌ Security risk
chmod -R 777 /var/www # ❌ Very dangerous!
# Don't remove execute from directories
chmod -x mydir # ❌ Can't cd in!
# Don't forget SSH key permissions
chmod 644 ~/.ssh/id_rsa # ❌ SSH refuses to use it
chmod 600 ~/.ssh/id_rsa # ✅ Required
# Don't set umask without understanding
umask 0000 # ❌ Everyone can read/write new files
# Don't forget to source after changing .bashrc
nano ~/.bashrc
# ... add umask ...
source ~/.bashrc # ✅ Required to apply
Common Pitfalls
| Pitfall | Problem | Solution |
|---|---|---|
| SSH key too permissive | SSH refuses | chmod 600 ~/.ssh/id_rsa |
777 on web files | Security hole | 644 files, 755 dirs |
Removed x from directory | Can’t cd in | Add x back |
umask not applied | Forgot to source | source ~/.bashrc |
Wrong id flag | Unexpected output | Check id --help |
| Chmod without permission | Owner or root only | sudo chmod ... |
Real-World Examples
1. Setting Up an SSH Key
# Generate key
$ ssh-keygen -t rsa
# Fix permissions
$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/id_rsa
$ chmod 644 ~/.ssh/id_rsa.pub
$ chmod 644 ~/.ssh/authorized_keys
2. Web Server Setup
# Directory
$ mkdir /var/www/mysite
$ chmod 755 /var/www/mysite
# Files
$ touch /var/www/mysite/index.html
$ chmod 644 /var/www/mysite/index.html
# Uploads directory (needs write)
$ mkdir /var/www/mysite/uploads
$ chmod 775 /var/www/mysite/uploads
3. Shared Team Directory
# Set group ownership
$ sudo chgrp developers /shared/project
$ chmod 775 /shared/project
# Set setgid so new files inherit group
$ chmod g+s /shared/project
# Set umask for team
$ echo "umask 002" >> ~/.bashrc
4. Private Workspace
# Restrict everything
$ umask 077
$ mkdir private
$ touch secret.txt
$ ls -la
drwx------ 2 kronos users 4096 private
-rw------- 1 kronos users 0 secret.txt
5. Check Current Identity
$ id
uid=1000(kronos) gid=1000(users) groups=...
$ id -Gn
users adm sudo developers
# Shows all groups — useful for permission debugging
Visual: How umask Works
Files: 666 - umask = result
666 - 022 = 644
Directories: 777 - umask = result
777 - 022 = 755
umask 022:
666 (rw-rw-rw-) 777 (rwxrwxrwx)
- 022 (----w--w-) - 022 (----w--w-)
──────────────── ────────────────
= 644 (rw-r--r--) = 755 (rwxr-xr-x)
umask 077:
666 (rw-rw-rw-) 777 (rwxrwxrwx)
- 077 (---rwxrwx) - 077 (---rwxrwx)
──────────────── ────────────────
= 600 (rw-------) = 700 (rwx------)
Summary
| Command | Purpose | Example |
|---|---|---|
id | Show user identity | id -Gn |
chmod | Change permissions | chmod 644 file.txt |
umask | Set default permissions | umask 022 |
Key takeaways:
idshows UID, GID, and all groups — use-u,-g,-G,-nfor specific infochmodchanges permissions in two ways:- Symbolic —
chmod u+rwx,g-wx,o=rx file(readable) - Octal —
chmod 640 file(concise)
- Symbolic —
- Octal values:
4=read,2=write,1=execute(add them up per group) umasksets default permissions for new files/directories- Files start at 666, directories at 777 —
umaskis subtracted - Common umask:
022→ files 644, dirs 755 - Make umask permanent in
~/.bashrc
Remember: These three commands are the access control trio:
id— “Who am I?”chmod— “What can I do?”umask— “What will new files look like?”
Use chmod 644 for files, chmod 755 for directories, and chmod 600 for secrets. Set your umask in ~/.bashrc so every new file has safe defaults. And never, ever use chmod 777 — it’s the fast track to a security breach!
Stop using slow, ad-bloated tool sites! 🤮
🔎 Search “KandZ Tools” on Google to use many professional utilities for free.
KandZ.me is the ultimate minimalist hub for:
✅ Finance (Mortgage, Interest, Inflation)
✅ Tech (Base64, JSON, Dev Suite, IP)
✅ Health (BMI, BMR, TDEE)
✅ Productivity (Timer, Workspace, QR)
⚡️ Fast & Private
🔒 No data leaves your device
💎 100% Free
🔗 Use it now: https://tools.kandz.me
🔖 Bookmark it—you’ll need it later!