Sobes.tech
Middle
201

How is access rights system organized in Linux?

Answer from AI

sobes.tech AI

Linux uses Discretionary Access Control (DAC). Permissions are assigned to users, groups, and others. For each of these three categories, read (r), write (w), and execute (x) permissions are defined.

ls -l # Example output of the ls -l command
# drwxr-xr-x 2 user group 4096 Oct 26 10:00 directory_name
# -rw-r--r-- 1 user group 1024 Oct 26 10:00 file_name

The first character indicates the file type (- for a regular file, d for a directory). The next nine characters represent permissions:

  • First three: Owner permissions (rwx)
  • Next three: Group permissions (r-x)
  • Last three: Others permissions (r-x)

Permissions can be changed using the chmod command, with octal or symbolic notation:

# Add write permission for group
chmod g+w some_file.txt

# Set read, write, and execute permissions for owner,
# read and execute for group,
# and only read for others (754 in octal)
chmod 754 some_other_file.txt

The owner of a file or directory can be changed with the chown command:

# Change owner to new_user
chown new_user some_file.txt

# Change owner to new_user and group to new_group
chown new_user:new_group some_file.txt

The group of a file or directory can be changed with the chgrp command:

# Change group to new_group
chgrp new_group some_file.txt

Additional special bits:

Symbol Description Usage
s SUID (Set User ID): When set on an executable file, the process runs with the permissions of the file owner, not the user executing it. Used for programs requiring elevated privileges, e.g., passwd.
s SGID (Set Group ID): When set on an executable file, the process runs with the permissions of the file's group. When set on a directory, new files created within will belong to that group. Less common on executables. Useful on directories for shared access.
t Sticky Bit: When set on a directory, files within can only be deleted or renamed by their owner, the owner of the directory, or root. Commonly used in /tmp to prevent users from deleting others' files, even if they have write permission.
# Example of a file with SUID
# -rwsr-xr-x 1 root root 50000 Oct 26 10:00 /usr/bin/passwd

# Example of a directory with SGID
# drwxrwsr-x 2 user shared_group 4096 Oct 26 10:00 shared_directory

# Example of a directory with Sticky Bit
# drwxrwxrwt 10 root root 4096 Oct 26 10:00 /tmp

These mechanisms together provide granular control over filesystem access in Linux.