Linux / Bash
Beginner
1 min read
Changing Permissions with chmod and Ownership with chown
Example
# ---- chmod: octal notation ----
chmod 755 script.sh # rwxr-xr-x
chmod 644 config.conf # rw-r--r--
chmod 600 ~/.ssh/id_rsa # rw------- (private key)
chmod 700 ~/.ssh/ # rwx------ (ssh directory)
# Apply recursively to a directory tree
chmod -R 755 /var/www/html/
# ---- chmod: symbolic notation ----
chmod u+x script.sh # Add execute for owner
chmod g+w shared.txt # Add write for group
chmod o-r private.txt # Remove read for others
chmod a+r public.txt # Add read for all (a = ugo)
chmod u=rw,g=r,o= file.txt # Set exact permissions with =
chmod +x deploy.sh # Add execute for everyone (shorthand)
# ---- chown: change owner ----
sudo chown alice file.txt # Change owner only
sudo chown alice:developers file.txt # Change owner and group
sudo chown :www-data /var/www/html/ # Change group only
sudo chown -R alice:alice /home/alice/ # Recursive ownership change
# ---- chgrp: change group ----
sudo chgrp developers project/
sudo chgrp -R www-data /var/www/
# Verify changes
ls -la file.txt
stat file.txt
Related Resources
Linux / Bash Reference
Complete tag & property list
Linux / Bash How-To Guides
Step-by-step practical guides
Linux / Bash Exercises
Practice what you've learned
More in Linux / Bash