0
0
Linux CLIscripting~5 mins

Numeric permission mode (755, 644) in Linux CLI - Commands & Configuration

Choose your learning style9 modes available
Introduction
Files and folders on Linux have permissions that control who can read, write, or run them. Numeric permission modes like 755 or 644 are a simple way to set these permissions quickly using numbers.
When you want to make a script executable by everyone but only editable by you.
When you want a file to be readable by everyone but only writable by the owner.
When setting permissions on a website folder so the server can read files but users cannot change them.
When you need to quickly fix permission issues on files or directories.
When automating permission settings in scripts or deployment processes.
Commands
This command sets the permissions of 'myscript.sh' so the owner can read, write, and execute it, while others can read and execute it. This is common for executable scripts.
Terminal
chmod 755 myscript.sh
Expected OutputExpected
No output (command runs silently)
This command lists the details of 'myscript.sh' including its permissions, so you can verify the changes made by chmod.
Terminal
ls -l myscript.sh
Expected OutputExpected
-rwxr-xr-x 1 user user 0 Apr 27 12:00 myscript.sh
-l - Shows detailed information including permissions, owner, size, and modification date.
This command sets the permissions of 'document.txt' so the owner can read and write it, but others can only read it. This is typical for text files.
Terminal
chmod 644 document.txt
Expected OutputExpected
No output (command runs silently)
This command shows the permissions and details of 'document.txt' to confirm the permission changes.
Terminal
ls -l document.txt
Expected OutputExpected
-rw-r--r-- 1 user user 0 Apr 27 12:01 document.txt
-l - Displays detailed file information including permissions.
Key Concept

If you remember nothing else from this pattern, remember: numeric modes like 755 and 644 are shorthand to quickly set who can read, write, or execute files.

Common Mistakes
Using chmod 755 on a file that should not be executable.
This makes the file executable by everyone, which can be a security risk or cause errors if the file is not a script or program.
Use chmod 644 for files that only need to be read and written by the owner, not executed.
Forgetting to check permissions after using chmod.
You might think permissions changed correctly but they did not, leading to access problems.
Always run ls -l to verify permissions after changing them.
Summary
chmod 755 sets a file to be executable by the owner and readable/executable by others.
chmod 644 sets a file to be readable and writable by the owner, readable by others, but not executable.
Use ls -l to check and confirm file permissions after changes.