System
chmod & chown CLI
chmod and chown commands for file permissions and ownership.
28 commands
Windows
MacOS
Linux
#permissions
#ownership
chmod Numeric
Owner rwx, group rx, others rx
chmod 755 script.sh
Owner rw, group r, others r
chmod 644 file.txt
Owner rwx, no access for others
chmod 700 private/
Owner rw only, no other access
chmod 600 secrets.conf
Full permissions for everyone
chmod 777 shared.txt
chmod Symbolic
Add execute permission for owner
chmod u+x script.sh
Add write permission for group
chmod g+w file.txt
Remove read permission for others
chmod o-r file.txt
Add read permission for all users
chmod a+r file.txt
Set exact permissions for each
chmod u=rwx,g=rx,o=r file.txt
Add execute for all users
chmod +x script.sh
chown Ownership
Change file owner to alice
sudo chown alice file.txt
Change owner and group
sudo chown alice:devs file.txt
Change group only
sudo chown :devs file.txt
Copy ownership from another file
sudo chown --reference=ref.txt f.txt
Recursive
Set permissions recursively
chmod -R 755 mydir/
Change ownership recursively
sudo chown -R alice:devs project/
Set 644 on all files recursively
find . -type f -exec chmod 644 {} +
Set 755 on all directories
find . -type d -exec chmod 755 {} +
Special Permissions
Set SUID bit on executable
chmod 4755 mybin
Set SGID bit on directory
chmod 2755 shared/
Set sticky bit on directory
chmod 1755 /tmp/shared/
Set SUID using symbolic mode
chmod u+s mybin
Set SGID using symbolic mode
chmod g+s shared/
Set sticky bit using symbolic mode
chmod +t /tmp/shared/
Quick Commands
Set read/write/execute for owner, read/execute for others
chmod 755 <file>
Change the owner and group of a file
sudo chown user:group <file>
Recursively set permissions on all files in a directory
chmod -R 644 <directory>