File Permissions¶
Understanding and managing file permissions on the cluster.
Understanding Permissions¶
Linux files have three types of permissions:
Permission |
Symbol |
Octal |
Description |
|---|---|---|---|
Read |
|
4 |
View file contents |
Write |
|
2 |
Modify file contents |
Execute |
|
1 |
Run as program/script |
Files also have three permission levels:
Level |
Description |
|---|---|
Owner |
User who owns the file |
Group |
Users in the file’s group |
Others |
All other users |
Important
On ARC systems the ‘other’ bit should most always be set to 0
chmod - Change Permissions¶
Modify permissions using octal values or their shorthand:
chmod [OPTION]... MODE FILE...
Common Permission Values¶
Octal |
Symbol |
Use Case |
|---|---|---|
750 |
|
Scripts, executables |
640 |
|
Regular files (default) |
600 |
|
Private files |
700 |
|
Private directories |
Warning
NEVER use permission mode 777 on files or directories. This grants anyone permissions to change or delete it.
Examples¶
chmod 755 script.sh # rwx for owner, rx for group/others
chmod 644 file.txt # rw for owner, r for group/others
chmod +x script.sh # Add execute permission
chmod -R 755 dir/ # Recursive permission change
chmod go=u-w # set permissions for group and other to be the same as user but without write
touch - Create or Update Files¶
Create empty files or update timestamps:
touch newfile.txt # Create empty file
touch file1.txt file2.txt # Create multiple files
touch existing.txt # Update timestamp
Viewing Permissions¶
ls -l file.txt
# Output: -rwxr-xr-x 1 username group 1234 Jan 1 12:00 file.txt
# ^^^^^^^^^
# Permission string
Tips¶
Regular files default to
644(rw-r–r–)Scripts need execute permission (
755)Use
chmod +xto add execute,chmod -xto removeDirectories need execute permission to be accessible