File Permissions and Ownership in Linux
File Permissions and Ownership in Linux
๐ File Permissions and Ownership in Linux
1. ๐ Default File Permissions & umask
Default permissions:
- Files:
666(read & write for all) - Directories:
777(read, write, execute for all)
- Files:
Actual permissions = Default -
umaskView current umask:
1
umaskExample: If
umaskis022, new file permission becomes644(666 - 022) and directory permission becomes755(777 - 022)
2. ๐ Reading ls -l Output
1
ls -l file.txt
Example output:
1
-rw-r--r-- 1 user group 1234 Jun 5 10:00 file.txt
| Part | Meaning |
|---|---|
- | File type (- = file, d = directory, l = symlink) |
rw-r--r-- | Permissions: owner (rw-), group (rโ), others (rโ) |
user | File owner |
group | Group owner |
1234 | File size |
Jun 5 10:00 | Last modified date |
file.txt | File name |
3. ๐งฎ Managing Permissions
a. Numeric (Octal) Permissions
| Digit | Meaning |
|---|---|
7 | rwx |
6 | rw- |
5 | r-x |
4 | r-- |
0 | --- |
1
chmod 755 myscript.sh # rwxr-xr-x
b. Symbolic (Text) Permissions
1
2
3
chmod u+x file.txt # Add execute for user
chmod g-w file.txt # Remove write for group
chmod o=r file.txt # Set read-only for others
c. Group Ownership and Permissions
Change owner:
1
chown username file.txtChange group:
1
chgrp groupname file.txtSet group and owner:
1
chown user:group file.txt
4. โ๏ธ Customizing File Creation Mask (umask)
View current umask:
1
umaskTemporarily set umask:
1
umask 027Permanently set:
Add to
~/.bashrcor/etc/profile:1
umask 027
This post is licensed under CC BY 4.0 by the author.