EMZETT.
Login

Users, groups and file permissions on Linux

In short: Every file belongs to a user and a group and has permissions for owner, group and others: read (r), write (w), execute (x). Administrator rights are obtained with sudo.

In more detail: The permission system separates users from each other and protects the system.

In detail

ls -l file.txt         # -rw-r--r-- 1 anna users 120 ...
chmod 640 file.txt     # owner rw-, group r--, others ---
chmod +x script.sh     # make executable
chown anna:users file  # change owner/group
sudo adduser max       # create user
sudo usermod -aG sudo max   # add to group sudo
id                      # own user ID and groups
  • Numbers: r=4, w=2, x=1. 755 = rwxr-xr-x, 644 = rw-r—r—.
  • root: the administrator (UID 0). Do not work as root all the time.
  • sudo: runs a command with admin rights, configured in /etc/sudoers (edit with visudo).
  • Special permissions: SetUID, SetGID, sticky bit (/tmp).
  • ACLs: finer permissions with setfacl.
  • User files: /etc/passwd, /etc/group, password hashes in /etc/shadow.
  • SELinux/AppArmor: additional access control, see SELinux and AppArmor.

See also: Linux file system hierarchy (FHS), Bash