In Linux, file permissions are essential to security and determine who can access, modify, or execute files and directories. Linux follows a robust permission system that provides fine-grained control over users, groups, and other entities.

Here's a brief overview of Linux users and permissions

User and Group Identifiers

In Linux, each user and group is assigned a unique identifier (ID) known as the User ID (UID) and Group ID (GID), respectively. The operating system uses these IDs internally to identify and manage user and group permissions and ownership.

Here are some critical points about user and group identifiers in Linux:

  1. User IDs (UID): Each user account in Linux is assigned a UID. The root user has a UID of 0, reserved for the superuser. Regular user accounts typically have UIDs starting from 1000 and incrementing sequentially. UID 1 is reserved for the daemon account, and other UIDs might be assigned to system accounts or services.

  2. Group IDs (GID): Similar to users, groups in Linux are assigned a GID. The root group usually has a GID of 0. Regular groups typically have GIDs starting from 1000 and incrementing sequentially. GIDs can be associated with multiple users, allowing users to share common permissions and access.

  3. /etc/passwd and /etc/group: User and group information, including their IDs, is stored in the system files "/etc/passwd" and "/etc/group". These files provide a mapping between user/group names and their respective IDs, along with other account-related information.

  4. Changing User and Group IDs: Changing user or group IDs should be done cautiously, as it can impact file ownership and permissions. The usermod command is used to modify user account properties, including the UID. The groupmod command is used to change group properties, including the GID.

  5. File Ownership: Each file and directory in Linux has an owner (user) and group associated with it. File permissions are enforced based on these ownership attributes. The owner of a file can modify its permissions, and the group permissions apply to all group members.

  6. UID and GID Conflicts: Conflicting UIDs or GIDs may lead to file ownership issues or access problems.

How to find the UID and GID

sudo cat /etc/passwd

The columns are as follows:

Permissions

Permissions are divided into 4 categories of users:

There can be a combination of read (r), write (w), and execute (x). They can be assigned easily with the plus and minus signs to add or remove certain permissions. These modifications are done using the chmod command.

Binary references

We can use numbers as well to set the permissions of a file. Here is a simple table to demonstrate this.

For example, we need to ensure that only I can view or modify my SSH keys directory. We can do this by running the following:

chmod 0600 ~/.ssh

This will deny all others the right to view the contents. I on the other hand will be able to read (4) and write (2).

Ownership

The chown command is used to set the ownership of a file.

chown kinaro:kinaro text.txt

This sets the ownership of the file to user 'kinaro' and group 'kinaro' as’.

Other Attributes

Significance of permissions

Restricting access to only the users that are allowed. A good example is a user's home directory. We do not want other users viewing their files and making changes. Another example would be configuration files. We don't want every user to be able to modify the bootloader, firewall, and system files.

The lead image for this article was generated by HackerNoon's AI Image Generator via the prompt "A door requiring biometric verification"