Informatec Digital » Linux » Permissions in Linux: Everything you need to know
- Linux uses a permission system that controls access to files and directories.
- Permissions are divided into read, write, and execute for owners, groups, and other users.
- Changing permissions can be done with the chmod and chown commands.
- Setting appropriate permissions is crucial to protect sensitive files and share them properly.
What are permissions in Linux?
Types of permissions in Linux
- Read permission (r): Allows a user to view the contents of a file or directory.
- Write permission (w): Allows a user to modify or delete a file or directory.
- Execute permission (x): Allows a user to execute a file or access a directory.
- Owner: The user who created the file or directory.
- Group (group): A set of users with similar permissions.
- Others: All other users who are not the owner or members of the group.
How to view file and directory permissions?
$ ls -l archivo.txt
-rw-r--r-- 1 usuario grupo 1024 jul 8 10:00 archivo.txt
Modifying permissions in Linux
Method 1: Modify permissions using the command chmod
$ chmod permisos archivo_o_directorio
- Numeric format: Permissions are represented by a three-digit number. Each digit represents permissions for the owner, group, and other users, respectively. Each permission is associated with a number: 4 for read, 2 for write, and 1 for execute. For example, the number 6 (
4 + 2) represents read and write permissions.
- Symbolic format: Permissions are represented using symbolic characters. You can use
+ To add permissions, - to remove permissions and = to set the exact permissions. For example, +x adds the execute permission.
$ chmod u+rw archivo.txt
$ chmod a+r archivo.txt
$ chmod o-x archivo.txt
Method 2: Modify permissions using octal numbers
| Excuse me |
Numerical value |
| Reading |
4 |
| Writing Instruments |
2 |
| Execution |
1 |
$ chmod 644 archivo.txt
Permissions in Linux: Common Use Cases
Use Case 1: Sensitive Configuration Files
$ chmod 640 database.conf
Use case 2: Sharing files and directories
$ chmod 770 directorio_compartido
$ chgrp grupo_compartido archivo.txt
Use case 3: Running scripts and programs
$ chmod +x script.sh
Frequently Asked Questions about Permissions in Linux
$ chmod +rw *.txt
$ chown nuevo_propietario archivo_o_directorio
$ chown nuevo_usuario archivo.txt
$ chmod -R +rw documentos
$ sudo chmod +x archivo.sh
Conclusion