- 8777701917
- info@saikatinfotech.com
- Basirhat W.B
Linux file permissions are a fundamental aspect of system security and user management. They define what actions a user or group can perform on files and directories. Linux file permissions are set for three types of users:
These permissions specify the types of access users have to files and directories, such as reading, writing, or executing them.
File permissions in Linux are represented by a 10-character string, which is displayed when using the ls -l
command. For example:
-rwxr-xr-x 1 user group 12345 Dec 21 12:00 file.txt
This string is divided into:
The first character of the permission string indicates the file type:
-
: Regular filed
: Directoryl
: Symbolic linkc
: Character device fileb
: Block device filep
: FIFO (named pipe)s
: SocketThe next 9 characters represent the permissions for the owner, group, and others. These are divided into three sets of three characters:
Each set consists of three characters:
r
: Read permission (allows viewing the contents of the file or listing the contents of a directory).w
: Write permission (allows modifying the contents of the file or creating/deleting files in a directory).x
: Execute permission (allows running the file as a program or script, or accessing a directory).If a permission is not granted, it is represented by a -
.
For example:
-rwxr-xr– 1 user group 12345 Dec 21 12:00 file.txt
rwx
(read, write, and execute).r-x
(read and execute).r--
(read only).Here’s a breakdown of the permission string:
Character Position | Description | Permissions |
---|---|---|
1 | File type | - (file), d (directory), etc. |
2–4 | Owner permissions | rwx or r-- , r-x , etc. |
5–7 | Group permissions | rwx , r-- , etc. |
8–10 | Others permissions | rwx , r-- , etc. |
chmod
To modify the permissions of a file or directory, you use the chmod
command. There are two ways to represent the permissions: symbolic mode and numeric mode.
In symbolic mode, you specify the permission change using letters:
u
: User (owner)g
: Groupo
: Othersa
: All users (owner, group, and others)The operators used are:
+
: Add a permission-
: Remove a permission=
: Set a permission exactly (overwrites existing permissions)
Example:
chmod u+x file.txt
: Adds execute permission to the owner of file.txt
.chmod g-w file.txt
: Removes write permission from the group.chmod o=r file.txt
: Sets read-only permission for others, removing any previous permissions.In numeric mode, permissions are represented by numbers. Each permission is assigned a number:
r
): 4w
): 2x
): 1
The permissions for owner, group, and others are then combined into a 3-digit number:
To calculate the numeric mode, you add up the values for the permissions you want to grant.
Permission | Read | Write | Execute | Numeric Value |
---|---|---|---|---|
None | 0 | 0 | 0 | 0 |
Execute | 0 | 0 | 1 | 1 |
Write | 0 | 2 | 0 | 2 |
Write + Execute | 0 | 2 | 1 | 3 |
Read | 4 | 0 | 0 | 4 |
Read + Execute | 4 | 0 | 1 | 5 |
Read + Write | 4 | 2 | 0 | 6 |
Read + Write + Execute | 4 | 2 | 1 | 7 |
Example:
chmod 755 file.txt
: Sets permissions to rwxr-xr-x
(owner: rwx
, group: r-x
, others: r-x
).7
(read + write + execute), group gets 5
(read + execute), others get 5
(read + execute).chown
The chown
command is used to change the owner and group of a file or directory. The syntax is:
Useful Options