Skip to content
Cameron edited this page Jan 28, 2017 · 1 revision

title: Chmod permalink: /Chmod/

CHMOD

Chmod command sets UNIX file permissions. First you need to TELNET or SSH to the target computer, then in the command prompt you need to execute a chmod command. Also you can set the permissions with the help of other programs, such as FTP client.

Syntax and examples of the shell chmod command (telnet or SSH)

Syntax of the chmod command is the following:

prompt> chmod [options] permissions file[s]

The word "chmod" should be entered all in lowercase letters. Options can be:

  • -R, set permissions recursively
  • -f, "forced" or silent mode
  • -v, "verbose", show information for every file processed
  • -c, show information only if changes are made to the file

Permissions could be one of the following:

  • Octal numeric format, with a leading zero like "0644"
  • Octal numeric format, without a leading zero like "644"
  • Text form like "a+r", "u=rwx" or "o-w", you can use several comma separated text form permissions

File[s] can be either

  • relative path to the file like "file.pl"
  • absolute path to the file like "/var/spool/mail/paul"
  • several space separated files like "file.pl /var/spool/mail/paul"
  • file name mask like "*.html" or "*"

What text permissions values mean:

  • u Sets permissions for the owner of the file, e.g.: "u+w" allows the owner to write to the file

  • g Sets permissions for the group (to which owner belongs), e.g. "g-x" suppresses the execution of the file by the group

  • o Sets permissions for other users (that are not in group), e.g.: "o=r" allows others only to read the file

  • a Sets permissions for all (owner, group and others), e.g.: "a-w" disables write access to the file for everyone

  • Assigns the permissions, e.g. "a

    rw", sets read and write permissions and disables execution for all

    • Removes certain thing[s] from the permissions, keeping all other (not involved) permissions. E.g. "a-x" disables execution of the file for everyone, this example doesn't touch read and write permissions.
    • Adds certain thing[s] to the permissions, keeping all other (not involved) permissions. E.g. "a+x" allows execution of the file for everyone, this example doesn't touch read and write permissions.
  • r Sets read permissions

  • w Sets write permissions

  • x Sets execute permissions

  • t Sets sticky bit, e.g. "o+t" sets sticky bit for a file

  • s Sets SUID or SGID. E.g.: "u+s" sets SUID, "g+s" sets SGID.

Examples

Here are the examples of the chmod command. All commands do the same thing, except that the first four set SUID & SGID and sticky bits to zero and the last two don't touch SUID & SGID and sticky bits:

  • prompt> chmod 0755 script.sh
  • prompt> chmod 755 script.sh
  • prompt> chmod u=rwx,g=rx,o=rx script.sh
  • prompt> chmod u=rwx,go=rx script.sh
  • prompt> chmod u+rwx,g+rx,g-w,o+rx,o-w script.sh
  • prompt> chmod u+rwx,go+rx,go-w script.sh

This example performs recursive chmod for the directory:

  • prompt> chmod -R 755 mydirectory

Performing chmod with FTP client program

When you set permissions in a GUI FTP client, you are usually presented with a more intuitive and clear interface than in a telnet program. You can easily see what permissions are set for owner/group/others. Here is the example of the chmod in FTP client:

In this example you see both table of the permission assignments, octal numeric value ("644" in the example) and the text value ("-rw-r-r" in the example). To set permissions in the FTP client, you usually select a group of files, and then either click a button, or a menu item. No need to type file names by hand or brainstorm an octal value to supply to chmod command.

At the same time, FTP servers usually supports limited chmod implementations, they do not allow to set the SUID, SGID or sticky bits.

Example FTP client programs: Filezilla

Difference between chmod from shell and FTP

As you can see above, using a GUI FTP client you have more clear and simple interface which is easier to use. But chmod command executed from the shell gives you an ability to set also setuid, setgid and sticky bits.

See also

In Video

{{#ev:youtube|VfKTvYFGEvs}} by danrulz98

Category:HOWTOs Category:Admin Category:FAQ

Clone this wiki locally