Ownership
drwxrwxr-x 2 root staff 4096 Sep 17 23:30 bin
(owner user) (owner group)
Change ownership:
sudo chown root alex_test.txt # change owner user to root
sudo chgrp root alex_test.txt # change owner group to root
Recursive change of all files in <Folder>:
chown -R root Somefolder # Somefolder - name of folder, where every user owner will be changed to root
Change of owner AND group:
sudo chown alex:admin alex_test.txt # change owner user to alex, owner group to admin
Permissions
drwxr-xr-x 2 alex alex 4096 Oct 8 15:52 Documents
1st letter: 'd'=directory,'l'=link,'-'=regular file;
The rest of the letters are divided in 3 groups of 3 letters: 'r'=read, 'w'=write, 'x'=eXecute.
Group 1: what permissions the owner has;
Group 2: what permissions the owner group has;
Group 3: what permissions everybody else has.
Octal numbers in permissions
Read = 4
Write = 2
Execute = 1
"rwx" = 7
"r-x" = 5
"rw-" = 6
"r--" = 4
Change permissions
chmod ugo-x alex_test.txt # change permissions to everyone ('ugo'=ownerUser, Group, Other), '-x' = deny execution
chmod u+x alex_test.txt # '+r'=allow execute of file by file owner
chmod 664 alex_test.txt # change permissions in octal mode ('664' = 'rw-rw-r--')
Changing default permissions
umask 022 # the default permissions, where 777 - 022 = 755 in octal = rwxr-xr-x for folders and rw-r--r-- for files (execute is disabled for files by default)
SUID
Set User ID bit - on executables.
If this bit is set, then the executable file will run with permissions of the owner of the file (usually root).
chmod u+s execfile # add SUID to exec file
GUID
Group User ID
If executable file, then it runs with permissions of the owner group ID. On folders: gives group ownership to any file inside this folder.
chmod g+s execfile # add GUID to exec file or folder
Sticky Bit
Used on folders, particularly on the /tmp (everybody writes there, need to protect from somebody deleting your files). It means that only the owner of the file, or the owner group member can delete the file.