The Short Answer
On Linux and Unix-like operating systems (including macOS), the chmod command is used to change the read, write, and execute permissions of a file or directory.
Executing the following command:
$ chmod 755 file.txt
Run in Warp
Will give:
- Read, write, and execute permissions to the owner of the file; which is the user account that created the file or has been assigned ownership of the file.
- Read and execute permissions to the group associated with a file; which is a collection of user accounts, such as members of the same team, that have been granted certain permissions on the file.
- Read and execute permissions to the others; which are all other users who are not the owner or members of the group associated with the file.
When using the symbolic notation, the 755 permissions translate to rwx r-x r-x.
chmod 755 on a directory
When applied to a directory as opposed to a single file, these permissions have a slightly different meaning:
- The read permission allows users to list the content of the directory (but only if the execute permission is also set).
- The write permission allows users to create, rename, and delete the entries of the directory.
- The execute permission allows users to enter (or traverse) the directory.
If you want to learn more about file permissions, you can read all about linux/unix permissions.
Using sudo With chmod 755
The sudo command is used to execute a command as the superuser (or root).
Executing the chmod command with sudo allows you to modify the permissions of a file or directory that you do not have access to as the current user.
For example, you can use the sudo chmod 755 command on a binary file to give permission to all users to execute it.
$ sudo chmod 755 script.sh
Run in Warp
As another example, you can use the same command on a directory, such as one containing server logs, to give permission to other users to read the logs file.
$ sudo chmod 755 /var/log/nginx
Run in Warp
It is important to note that giving the read and execute permission to all users to a file or directory may lead to security vulnerabilities, especially if it contains sensitive information or has the ability to execute arbitrary code.
If you want to learn more about the chmod command, you can read about the chmod command more broadly.
The difference between chmod 755 And chown 755
Often mistaken for each other, chmod and chown are two different commands that serve a distinct purpose.
The chmod command is used to change the permissions of a file or directory, while the chown command is used to transfer the ownership of a file or directory to another user or group.
Since the chown command allows you to either use symbolic names (e.g. foobar) or identifiers (e.g. 1001) to specify the user or group you want to transfer the ownership of a file to, you have to make sure not to mistake them with numeric permissions, such as the ones used with the chmod command.
For example, this command will change the permissions of the target file:
$ chmod 755 file
Run in Warp
While this command will transfer the ownership of the target file to the user identified on the system by the UID 755:
$ sudo chown 755 file
Run in Warp
Written by
Razvan Ludosanu
Founder, learnbackend.dev
Filed Under
Related Articles
List Open Ports in Linux
Learn how to output the list of open TCP and UDP ports in Linux, as well as their IP addresses and ports using the netstat command.
Count Files in Linux
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
How to Check the Size of Folders in Linux
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Linux Chmod Command
Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.
POST JSON Data With Curl
How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.
Format Command Output In Linux
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Create Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
Switch Users In Linux
Learn how to switch between users, log in as another user, and execute commands as another user in Linux.
Remover Users in Linux
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.
Delete Files In Linux
Learn how to selectively delete files in Linux based on patterns and properties using the rm command.
Find Files In Linux
Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.
Copy Files In Linux
Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.