1 | 2 | 3 | page 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11
There will be many instances of server administration that you will need to change the file permissions. The command chmod allows you to modify the read, write, and execute permission. chmod can only change permissions to files that allow the user issuing the command to do so. To change permissions of files and directories regardless of the current file permission setting, you need root authority.

The file permission or access right can be set to -, r, w, x using the numeric code 0, 4, 2, or 1, respectively, as summarized in the following table.

Code Description
0 or - The access right that is supposed to be on this place is not granted.
4 or r read access is granted to the user category defined in this place.
2 or w write permission is granted to the user category defined in this place.
1 or x execute permission is granted to the user category defined in this place.

To access each group of users (owner, group, others), the following group codes are used as following.

Code Description
u user permissions
g group permissions
o permissions for others

The folowing table illustrates how to use chmod to perform file protection by changing the appropriate access rights for the file owner, owner group, and other users. The file permission can be set with numeric or alphabetical codes.

File protection with chmod
Code Description
chmod 400 file Set the file permission to r-------- to protect a file against accidental overwriting. The file cannot be modified by its owner or anyone else. Only the file owner can read the file. This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+r file
chmod u-wx file
chmod go-rwx file
chmod 500 directory Set the file permission of a directory to read-only and do not allow anyone else to access the directory to protect yourself from accidentally removing, renaming or moving files from this directory (r-x------). This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+rx directory
chmod u-w directory
chmod go-rwx directory
chmod 600 file Set the file permission of a file to allow read/write access by only its owner (rw-------). This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+rw file
chmod u-x file
chmod go-rwx file


Code Description
chmod 644 file Set the file permission of a file to allow read access by anyone, but only the file owner can change it (rw-r-r-). This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+rw file
chmod u-x file
chmod go+r file
chmod go-wx file
chmod 660 file Set the file permission of a file to rw-rw---- so that users belonging to your group can change this file, and disallow others to access it. This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+rw file
chmod u-x file
chmod g+rw file
chmod g-x file
chmod o-rwx file
chmod 700 file file Set the file permission of a file to rwx------ to protect a file against any access from other users, while the issuing user still has full access. This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+rwx file
chmod go-rwx file
chmod 755 directory Set the file permission of a directory so that files in the directory are readable and executable by anyone else, but only the file owner can change it (rwxr-xr-x). This is a quick way to perform the equivalent commands using alphabetical codes.
chmod u+rwx directory
chmod go+rx directory
chmod go-w directory
chmod 775 file Set the file permission of a file to rwxrwxr-x. This is the standard file sharing mode for a group. Other users can read and execute the file but cannot modify it. This is a quick way to perform the equivalent commands using alphabetical codes.
chmod ugo+rwx file
chmod o-w file
chmod 777 file Set the file permission of a file to rwxrwxrwx. Anyone can do whatever they want to this file. This is equivalent to chmod ugo+rwx file. Be extra careful when doing this as root since it can compromise the security of your server if mistakes are committed. Issuing chmod 777 -r / while logging in as root will destroy your server's file system and will require a reinstallation of the os.

Setting the file permission with chmod can be applied to a directory and all its files and subdirectories via the option chmod -R or chmod --recursive. Be very careful when using this option while having root authority, since mistakes here are very costly.
1 | 2 | 3 | page 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11