Back
Linux File Permissions
Confession of a Web Dev: File Permissions
As a web developer, I rarely deal with Linux file permissions. It's a simple concept, but the specifics are easy to forget. This recently became clear when I was setting up Git with an SSH key. The default permissions allowed anyone in my group to modify the key file, which caused Git to reject it (security first, I guess!).
A quick web search (minus the AI) led me to this helpful blog post: "Getting to Know Linux File Permissions" by Linux.com. It provided a clear explanation that refreshed my memory and got me back on track.
tdlr;
- Use
ls -l
to view file permissions- The returned structure is [fileType][filePermissions] [numberOfLinks] [ownerName] [groupName] [fileSizeInBytes] [date] [file]
- Example
-rw-r--r-- 1 owner1 staff 675 Feb 8 19:10 package.json
- File Permissions sections
- [filePermissions] === [user][group][others] ===
rwxrwxrwx
- [filePermissions] === [user][group][others] ===
- File permissions (or mode) is modified with
chmod
command using:- Absolute Mode (or Binary Representation):
- Use octal digit (digits 0-7) for each section
- Each octal digit can be broken down into binary with value ranging
- Examples:
- Binary value of
000
for [user] ischmod 000 package.json
and means the user has no permissions for the given file - Binary value of
001
for [user] ischmod 100 package.json
and means the user has execute permissions and can run the given file - Binary value of
010
for [user] ischmod 200 package.json
and means the user has write permissions and can change the given file - Binary value of
011
for [user] ischmod 300 package.json
and means the user has write and execute permissions and can change and run the given file - Binary value of
100
for [user] ischmod 400 package.json
and means the user has read permissions and can view the contents for the given file - Binary value of
101
for [user] ischmod 500 package.json
and means the user has read and execute permissions and can view the contents for and execute the given file - Binary value of
110
for [user] ischmod 600 package.json
and means the user has read and write permissions and can view the contents for and change the contents of the given file - Binary value of
111
for [user] ischmod 700 package.json
and means the user has read, write, and execute permissions and can view the contents for, change the contents of, and run the given file
- Binary value of
- Use octal digit (digits 0-7) for each section
- Symbolic Mode:
- Use characters u, g, or o for each section
- Able to add permission (+), remove permission (-), or copy permissions (=)
- Examples:
chmod o+r package.json
adds read permissions for others for the given filechmod g+w package.json
adds write permissions for the group for the given filechmod u+x package.json
adds execute permissions for the user for the given filechmod u+rwx package.json
adds read, write, and execute permissions for the user for the given filechmod g=u package.json
copy the user's permissions to the group's permissions for the given file
- Absolute Mode (or Binary Representation):
Additional Reference
View the Manual pages for more details
- In a linux terminal, run
man ls
orman chmod
- Visit web page for the ls manual
- Visit web page for the chmod manual