Linux Permissions
Read, understand, and change file permissions and ownership β a skill DevOps engineers use every day.
One of the biggest reasons Linux is trusted to run the worldβs servers is its powerful permission system. Permissions decide who can read, modify, and execute each file. Without them, any user could change or delete critical system files.
π― Learning Objectives
By the end of this lesson you will:
- Understand users and groups
- Read Linux permission strings
- Change permissions with
chmod - Change ownership with
chown - Understand why permissions matter in DevOps
Reading Permissions
Run ls -l and youβll see a permission string at the start of each line:
That string breaks down into three groups of three:
- rw- r-- r--
β β β βββ Others : read
β β ββββββββ Group : read
β βββββββββββββ Owner : read + write
βββββββββββββββββ file type ( - = file, d = directory )
r = read w = write x = executeChanging Permissions with chmod
Make a script executable:
chmod +x deploy.sh # add execute permission
chmod -x deploy.sh # remove execute permissionAfter chmod +x, the permission string gains an x: -rwxr-xr-x.
Numeric (octal) permissions
Linux also lets you set permissions with numbers β read = 4, write = 2, execute = 1, added together per group:
| Number | Permission | Meaning |
|---|---|---|
| 7 | rwx |
read + write + execute |
| 6 | rw- |
read + write |
| 5 | r-x |
read + execute |
| 4 | r-- |
read only |
The most common command youβll type:
chmod 755 deploy.sh # owner: rwx, group: r-x, others: r-xChanging Ownership with chown
The first two names in ls -l are the owner and the group. To change ownership:
sudo chown ubuntu deploy.sh # make 'ubuntu' the ownerReal DevOps Example
A deployment script that isnβt executable fails with a clear error β and the fix is one command:
This is something DevOps engineers do regularly.
π§ͺ Hands-on Lab
Make a Script Executable
- Create a file named
test.sh - Check its permissions with
ls -l - Add execute permission with
chmod +x - Check the permissions again β notice the
xappear
β Never chmod 777 everything
chmod 777 gives everyone full read/write/execute access. Itβs a common beginner shortcut and a serious security risk. Follow the principle of least privilege β grant only the access actually needed.
π§ Knowledge Check
Which command changes a file's permissions?
What access does chmod 755 grant to the file's owner?
πΌ Interview Preparation
Explain what chmod 644 and chmod 755 mean and when you'd use each.
Summary
You now understand one of Linuxβs most important security features. Every DevOps engineer works with chmod, chown, and permission strings almost daily.