File System and Permissions
Since Linux is a multi-user system, access control for files and directories is strictly enforced.
1. Checking Permission Structure
Using the ls -l command displays information in the following format:
-rwxr-xr--
Out of these 10 characters:
- The first character:
-(File),d(Directory) rwx(2–4): Owner permissionsr-x(5–7): Group permissionsr--(8–10): Others permissions
Meaning of Each Character
r(Read, 4): Permission to read the file.w(Write, 2): Permission to write to or modify the file.x(Execute, 1): Permission to execute the file.
2. Changing Permissions (chmod)
Permissions are set using the sum of these values: (r=4, w=2, x=1)
# Grant 7 (rwx) to the owner, 5 (r-x) to the group, and 5 (r-x) to others
chmod 755 script.sh
# Grant read/write permissions to all users
chmod 666 data.txt
3. Changing Ownership (chown)
# Change the ownership of index.html to user 'ubuntu' and group 'ubuntu'
sudo chown ubuntu:ubuntu index.html
4. Superuser Privileges (sudo)
sudo (SuperUser DO) is used to execute commands with administrative (root) privileges. For security reasons, it should only be used when necessary, such as for installing packages or modifying system configuration files.
In the next section, we will learn about shell scripting, which allows you to bundle and execute these commands together.