You try to run a script in the terminal, but all you get is a short, frustrating reply: Permission denied. Almost everyone who is new to Linux runs into this message. The reason is usually simple: the file's permissions don't allow the operation you're trying to perform. In this article, we explain Linux file permissions from scratch and use practical examples to show how to read ls -l output, how to use the chmod and chown commands, what numbers like 755 and 644 mean and which mistakes to avoid.
What are Linux file permissions and why do you need them?
Linux was designed as a multi-user system from the very beginning: several people, as well as services such as a web server or a database, run on the same server under separate user names. If everyone could touch every file, it would cause problems for both security and stability. That's why every file and directory has an owner (user), a group and separate permissions for three categories:
- u (user) — the owner of the file;
- g (group) — members of the group the file belongs to;
- o (others) — all other users on the system.
Each category is assigned three basic rights:
- r (read) — read;
- w (write) — write, modify;
- x (execute) — execute (run as a program or script).
One more thing to keep in mind: the root user bypasses most of these restrictions. That's exactly why it's recommended to do your everyday work as a regular user and run administrative commands with sudo only when necessary.
How to read ls -l output
To view permissions, use the ls -l command. Let's look at an example:
$ ls -l
-rwxr-xr-- 1 aysel developers 2048 Nov 20 10:15 backup.sh
drwxr-x--- 2 aysel developers 4096 Nov 20 10:10 reports
The ten characters at the start of the line are the most important part. You can break them down like this:
- The first character shows the file type:
-is a regular file,dis a directory andlis a symbolic link. - The next three characters (
rwx) are the owner's permissions. - The following three characters (
r-x) are the group's permissions. - The last three characters (
r--) are the permissions for other users.
A hyphen (-) means that the right is not granted. So aysel, the owner of backup.sh, can read, modify and execute it, members of the developers group can read and execute it, and everyone else can only read it. The words aysel and developers in the line show the owner and the group, respectively.
r, w and x mean different things for files and directories
This is where beginners get confused most often. For directories, the same letters mean something slightly different:
- r — see the names of the files in the directory (
ls); - w — create, delete and rename files in the directory (this also requires the
xright); - x — enter the directory (
cd) and access the files inside it.
This leads to an interesting conclusion: the right to delete a file depends not on the file's own permissions but on the permissions of the directory it's in. Even if you don't have write permission on the file itself, you can delete it if you have w and x on the directory.
chmod: changing permissions with symbolic notation
To change permissions, use the chmod (change mode) command. In symbolic notation, you specify who it applies to (u, g, o, or a for all), which operation to perform (+ to add, - to remove, = to set exactly) and which right:
chmod u+x backup.sh # add execute permission for the owner
chmod go-w notes.txt # remove write permission from the group and others
chmod o= secret.txt # remove all permissions for others
chmod a+r README.md # give everyone read permission
chmod u=rw,g=r,o= app.conf
Symbolic notation is handy when you only need to change some of the existing permissions, because it leaves the rest untouched.
chmod: numeric (octal) notation and what 755 and 644 mean
In numeric notation, each right has its own value: r = 4, w = 2, x = 1. A category's permissions are written as the sum of these values. For example, rwx = 4 + 2 + 1 = 7, r-x = 4 + 1 = 5, r-- = 4. The three digits represent the owner, the group and others, in that order.
These are the combinations you'll see most often in practice:
- 755 (
rwxr-xr-x) — for scripts, programs and directories: the owner can do everything, while others can read and execute; - 644 (
rw-r--r--) — for regular text and configuration files; - 700 (
rwx------) — a private directory or script that belongs only to the owner; - 600 (
rw-------) — sensitive files, such as SSH keys and configuration files that store passwords.
chmod 755 deploy.sh
chmod 644 index.html
chmod 600 ~/.ssh/id_ed25519
Numeric notation sets all permissions precisely in one go, which is why it's used more often when setting up servers and in documentation.
Why is chmod 777 a bad idea?
Some "solutions" on the internet suggest running chmod 777 whenever a permission problem comes up. This makes the file writable and executable by everyone on the system. The problem is "solved" for the moment, but it opens a serious security hole: any user or compromised service can modify the file. The right approach is to find the cause of the problem and grant only the necessary right to the category that needs it.
chown and chgrp: changing ownership
Sometimes the problem isn't the permissions but the file's owner. For example, if you created a file with sudo, its owner is root, and you can't edit it as a regular user. That's where chown (change owner) comes in:
sudo chown aysel report.txt # change the owner
sudo chown aysel:developers report.txt # change the owner and group together
sudo chgrp developers report.txt # change only the group
sudo chown -R www-data:www-data /var/www/site # the directory and everything in it
The -R option makes the operation recursive, applying it to all files and subdirectories inside the directory. Use this option with care: a recursive command run on the wrong directory can break the system. Note that changing a file's owner usually requires root privileges.
A practical scenario: fixing the "Permission denied" error
Let's write a small script and get it working step by step:
$ nano hello.sh
#!/bin/bash
echo "Hello, Linux!"
$ ./hello.sh
bash: ./hello.sh: Permission denied
$ ls -l hello.sh
-rw-r--r-- 1 aysel aysel 34 Nov 24 09:00 hello.sh
$ chmod u+x hello.sh
$ ./hello.sh
Hello, Linux!
What happened here? The newly created file didn't have the execute (x) right. We gave the owner this right with chmod u+x, and the script ran. The #!/bin/bash line (the shebang) at the top of the file tells the system which interpreter to use to run the script.
Another typical example is SSH keys. If a private key file's permissions are too open (for example, if other users can read it), the OpenSSH client shows a warning and refuses to use that key. The fix is to make the key accessible only to its owner: chmod 600 ~/.ssh/id_ed25519.
umask: where do the permissions of new files come from?
Have you ever wondered why the files you create get 644 permissions and directories get 755? This is determined by the umask. The system starts from a base value of 666 for files and 777 for directories and subtracts the rights specified in the umask. With a umask of 022, files are created with 644 and directories with 755. To see the current value, just type umask in the terminal. Depending on the distribution and the type of user, the default value may be 022 or 002.
Special permissions: SUID, SGID and the sticky bit
In addition to the basic permissions, Linux has three special flags. At the beginner stage, it's enough to know what they are:
- SUID — the program runs with the rights of the file's owner rather than the user who launched it. The classic example is the
passwdcommand: a regular user can change their own password even though they don't have direct write access to the file where passwords are stored. - SGID — when applied to a directory, new files created in it inherit the directory's group. This is useful for shared team directories.
- Sticky bit — in a directory that everyone can write to, each user can delete only their own files. The
/tmpdirectory is a good example: in the output ofls -ld /tmp, you'll see the lettertat the end of the permission string.
Common mistakes and useful habits
- Trying to solve every problem with
sudo. This mixes up file ownership and creates new permission problems later. Check the situation withls -lfirst. - Forgetting the
xright on directories. If a directory hasrbut notx, you can't access the files inside it. - Applying the same recursive permissions to files and directories.
chmod -R 755makes all regular files executable as well. A cleaner way is to handle them separately:
find /var/www/site -type d -exec chmod 755 {} +
find /var/www/site -type f -exec chmod 644 {} +
- Not checking after making changes. It's a good habit to look at the result with
ls -lafter everychmodandchowncommand. For more detailed information, you can also usestat filename.
Conclusion
At first glance, Linux file permissions look like a confusing mix of letters and numbers, but once you understand the logic, everything falls into place: three categories (owner, group, others), three rights (read, write, execute) and a few commands to manage them — ls -l, chmod, chown, chgrp. This is a fundamental skill for anyone who wants to become a system administrator, DevOps engineer, backend developer or cybersecurity specialist, because a large share of server problems come down to permissions and ownership.
If you want to learn Linux systematically, with an experienced instructor and hands-on labs, take a look at the Linux Foundation course. Alongside the terminal and the file system, the course gives you practical experience with managing users and groups, permissions, packages, processes, shell scripting and Linux networking.