Bash Tutorial · Linux System Skills · Lesson 24 of 30
Bash File Permissions
Read and change file permissions with ls -l, chmod and umask, and understand owners and groups.
Reading permissions
ls -l shows something like -rwxr-x---: the type (- file, d directory), then read/write/execute for the
owner, the group and others.
chmod
- Symbolic:
chmod u+x script.sh,chmod go-w file,chmod -R a+r public/ - Numeric: r=4, w=2, x=1 per class:
chmod 755(rwxr-xr-x),chmod 644(rw-r--r--),chmod 600(private)
touch script.sh secret.key public.txt
chmod 755 script.sh
chmod 600 secret.key
chmod u=rw,go=r public.txt
ls -l script.sh secret.key public.txt | awk '{ print $1, $NF }'
stat -c '%a %n' script.sh secret.key public.txt
umask
Output
-rw-r--r-- public.txt -rwxr-xr-x script.sh -rw------- secret.key 755 script.sh 600 secret.key 644 public.txt 0002
Run this on your computer — see “Get Started” for setup.
chown user:group file changes the owner (usually needs sudo). umask sets the default permissions for new
files.
Never fix a permissions problem with chmod 777: it lets every user on the machine change the file.
Test yourself
What does chmod 600 key.pem allow?
Everyone can read itOnly the owner can read and write itOnly the owner can execute itNobody can access it
Show answer
Answer: Only the owner can read and write it