Chmod help

Visafoto.com by ZZEE - passport and visa photo online
Passport photo online
  • We know all visa and passport photo exact requirements for countries like US, Canada, UK, India, China, Russia, Australia, New Zealand, etc
  • You take a snap of yourself and we convert it into a correct visa or passport photo in seconds
  • Visafoto.com does everything automatically:
    • Scale and crop your photo up to requirements
    • Fix head tilt
    • Fix background
Passports * Visas * Student IDs

1. What is a chmod command?

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.

2. 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:

Permissions could be one of the following:

File[s] can be either

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.

2.1. 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

3. 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 Webmaster 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.

4. 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.

5. Advanced

5.1. Symbolic links

You can not change the permissions of the symbolic link (which always look like lrwxrwxrwx), and if you put a name of the symbolic link into chmod command, it will change the permissions of the file that the link points to.

6. Links

© 1999-2016 ZZEE, Terms of use