# chmodChange permissions
Syntax chmod mode file
$ chmod 644 index.htmlCopy
Owner reads and writes; everyone else reads
$ chmod 755 deploy.shCopy
Everyone can run it; only the owner can change it
$ chmod 600 ~/.ssh/id_ed25519Copy
Private keys must be readable only by you
$ chmod +x script.shCopy
Make a file runnable
$ chmod -R g+w /srv/sharedCopy
Give the group write access to a whole folder
Tip The three digits are owner, group and others. 4 = read, 2 = write, 1 = run, and you add them up: 6 = read + write, 7 = all.
# chownChange the owner
Syntax chown owner[:group] file
$ sudo chown deploy file.txtCopy
Make deploy the owner
$ sudo chown deploy:www-data file.txtCopy
Change owner and group together
$ sudo chown -R www-data:www-data /var/www/siteCopy
Apply to a whole folder
# chgrpChange the group
Syntax chgrp group file
# umaskDefault permissions for new files
Syntax umask [mask]
# sudoRun one command as the administrator
Syntax sudo command
$ sudo apt updateCopy
Run a command as root
$ sudo -iCopy
Open a root shell (type exit to leave)
$ sudo -u postgres psqlCopy
Run a command as another user
$ sudo !!Copy
Repeat the previous command with sudo
Careful sudo cd does not work. cd is built into the shell, so sudo cannot start it. Use sudo -i for a root shell, or sudo ls /folder to look inside.
Switch user
Syntax su [-] [user]
# whoamiShow who you are logged in as
Syntax whoami
$ whoamiCopy
Prints your user name
Show your user and group numbers
Syntax id [user]
# groupsList groups
Syntax groups [user]
$ groupsCopy
Groups you are in
# getfacl / setfaclFine-grained permissions (ACL)
Syntax setfacl -m u:user:rwx path