Home > File & Directory Management > chmod

Mastering the chmod Command

A guide to the chmod command in Linux, used for changing file and directory access permissions. Easily understand and apply permission settings with this tool.

Key Options

Combine various `chmod` command options to set permissions for files and directories.

1. Permission Setting Methods

2. Additional Options

Generated command:

Try combining the commands.

Description:

`chmod` Executes the command.

Combine the above options to virtually execute commands with AI.

Understanding Permissions

Linux file permissions consist of Read, Write, and Execute permissions for the Owner (User), Group, and Others. Combinations of these permissions can be expressed using numeric (octal) or symbolic characters.

Octal Permission Values

Each permission can be represented by a number. The sum of these numbers defines the permissions for each user type (owner, group, others), which are then combined to form a 3-digit octal mode.

  • 4: Read (r)
  • 2: Write (w)
  • 1: Execute (x)
  • 0: No permission (-)

Understanding Symbolic Mode

Symbolic mode changes permissions in the form 'target (u:user, g:group, o:others, a:all) + operator (+:add, -:remove, =:set) + permission (r,w,x)'. For example, u+x adds execute permission for the owner, and go=rw sets read/write permissions for group and others.

Common Octal Permission Examples Meanings of frequently used octal permission modes.
Mode Description Symbolic
777 All permissions for everyone (Read, Write, Execute) rwxrwxrwx
755 Owner: all permissions; Group/Others: Read/Execute rwxr-xr-x
644 Owner: Read/Write; Group/Others: Read-only rw-r--r--
600 Owner: Read/Write; Group/Others: No permissions rw-------

Usage Examples

Practice setting permissions through practical usage examples of the `chmod` command.

Allow only the owner to read and write a file (600)

chmod 600 myfile.txt

Blocks access to the file for other users, allowing only the owner read/write permissions. This is one of the most secure file permissions.

Add execute permission to a script file

chmod +x myscript.sh

Makes a script file executable by all users. Used for web server scripts, etc.

Recursively change permissions of a directory and its sub-files (755)

chmod -R 755 mydir/

Recursively applies 755 permissions to a directory and all its files/subdirectories. Useful for static file directories of web servers, etc.

Remove write permissions for group and other users

chmod go-w important_file.conf

Removes write permissions for the group and other users from a file. This helps enhance security.



Same category commands