chmod (change file permissions)

The chmod (“change mode bits”) command is used to edit a file's access permissions. It should go without saying that only a file's owner is allowed to change its permissions. An exception to this is root, who may edit the status of any file. The most general form of chmod is this:

chmod ugo=rwx FILE

This gives the file's user/owner (u), group (g) and all others (o) the permission to read (r), write (w) and execute (x) FILE. You should not use this combination of options for two reasons. First, there is a shorthand for giving everybody the right to do everything with FILE:

chmod a=rwx FILE

The letter a is for “all”, that is, user, group and others. Second, you should usually assign permissions more selectively. A good default value is rwxr-xr-x, where the file's user has all rights, while group and others are not allowed to edit or delete the file. You can set these permissions like this:

chmod u=rwx,go=rx

Sometimes it's faster to remove or add particular permissions. This is done using the plus (+) and minus (-) operators. For example:

chmod o-r FILE

This will remove others' permission to read FILE. Finally, have a look at this particularly common example:

chmod a+x FILE

When you download a program from the Internet, you can use chmod a+x to make it executable.