This 3‑hour module equips students with the skills to set, modify, audit and troubleshoot Linux file and directory permissions and ownership. The plan is designed for users who already know how to navigate the filesystem and want to enforce security policies.
ls -l and stat.umask to control default permission bits.getfacl and setfacl.find with -perm, -user, -group.ls -l (5 min)chmod (10 min)chown & chgrp (10 min)umask (10 min)getfacl & setfacl (15 min)stat, find -perm, find -user (15 min)ls -l – List with PermissionsShows file mode, owner, group, size and timestamps.
ls -l /home/youruser ls -l file.txt
/tmp and interpret each column.stat – Detailed File InformationDisplays inode, device, permissions, ownership, timestamps, etc.
stat file.txt stat --format '%A %n' file.txt
stat /etc/passwd and copy the permissions string.ls -l.chmod – Octal NotationSets permissions by numeric value.
chmod 644 file.txt chmod 600 script.sh chmod 777 directory
readme.txt and set it to 644.runme.sh readable by everyone but only executable by the owner (755).chmod – Symbolic NotationUses characters to modify permission bits.
chmod u+x file.txt chmod g-w file.txt chmod o= file.txt chmod u=rwx,g=rx,o= file.txt
readme.txt with chmod g-w.readme.txt with chmod o=.chown – Change OwnerReassigns file or directory owner (and optionally group).
chown user file.txt chown user:group file.txt chown -R user:group dir/
file.txt to root.chgrp – Change GroupReassigns the group of a file or directory.
chgrp staff file.txt chgrp -R staff dir/
devops (if you have sudo).script.sh into /tmp and set its group to devops.umask – Default Permission MaskDefines the default permission bits for newly created files/directories.
umask umask 022 umask 027 umask 077
umask value.027, create a new file, and confirm the file has 640 permissions.getfacl – Display ACLsShows extended ACL entries for a file or directory.
getfacl file.txt getfacl -R dir/
/tmp if it’s not already enabled.getfacl /etc/hosts and copy the output.setfacl – Modify ACLsAdds or removes ACL entries.
setfacl -m u:alice:rw file.txt setfacl -m g:devops:r-- dir/ setfacl -b file.txt # remove all ACLs
alice read/write access to readme.txt without altering the existing permissions.devops read-only access to directory /tmp/dev.find -perm – Search by Permission BitsFinds files that match specific permission patterns.
find . -perm 644 -type f find /tmp -perm /g=w # files writable by group find /tmp -perm -g=w # files with group write bit set
/tmp for all files that are world‑executable.find -user/-group – Search by Owner or GroupLocates files based on current owner or group.
find /var/log -user root -type f find /tmp -group staff -type d
root in /var.devops.chmod g+s – SetGID on a DirectoryEnsures new files inherit the directory’s group.
chmod g+s project/ ls -ld project/
/tmp/project.chmod +t – Sticky BitPrevents users from deleting files that they don’t own in a shared directory.
chmod +t /tmp/shared ls -ld /tmp/shared
/tmp/shared.getent passwd / getent group – View Users & GroupsDisplays the system’s user and group database.
getent passwd | grep alice getent group | grep devops
bob and copy the GECOS field.staff.id – Show User/Group IDsPrints real, effective, saved, and supplementary group IDs.
id id alice id -Gn
id and map the numbers to usernames by using getent passwd.id -Gn.auditd – Permission Auditing (optional)Demonstrates how to audit permission changes.
# install auditd on the test machine sudo apt-get install auditd sudo auditctl -w /home/youruser -p wa -k home_changes sudo ausearch -k home_changes
/home/youruser/tmpfile, change its permissions, and verify the audit log shows the event.auditctl -W /home/youruser.Students are paired and each receives a /tmp/perm_tutorial folder pre‑populated with files and directories of varying ownership/permissions. They will complete all the exercises, then exchange their setups for peer review.
ls -l or stat before changing.-i with chmod / chown when experimenting./tmp/safe with permissions 2750 (setgid + r-x for owner & group)..conf files from /etc into it.alice full access while denying all other users.getfacl.Feel free to adjust the pacing or replace optional commands (e.g., auditd) with other tools such as selinux commands if your audience already knows ACLs.