PDA

View Full Version : FTP/Linux CHMOD Tips


Keefe
06-30-2001, 03:27 PM
Chmod is another innocuous but extremely useful Linux command. What does chmod do? Simply put, chmod allows you to change file permissions. For MS-DOS users, it is many ways similar to the "attrib" command, except in many ways it is more flexible and powerful.


Chmod recognizes four classes of users; user [u], group [g], other [o] and all [a]. These distinctions allow you to tailor permissions without having a blanket effect across the entire system, unless you specify it. With chmod you can either allow [+] or deny [-] the ability to run [r], write [w], or execute [x] a file.


Using chmod

The standard syntax is as follows:


chmod [u|g|o|a][+|-][r|w|x] filename



The [u|g|o|a] represent the user specification.
The [+|-] represents whether you wish to allow or deny access.
The [r|w|x] represent the functions you wish to allow or deny.

When you type the command, there is a space between chmod and the commands and a space between the commands and the filename. However, there is no space between the commands.


For example, "chmod go-rw filename" is an example if you what to remove the read and write permissions from the group and other categories.


Absolute setting

Another way to use chmod is through the absolute setting. The absolute setting replaces the commands [u|g|o|a][+|-][r|w|x] with octal numbers. Octal numbers are a numeric system based on eight (hence the octal). Instead of the [u|g|o|a][+|-][r|w|x] commands, you would use the numbers 0-7 to set permissions.

Here are the absolute settings and their permissions.


Setting SPAM SPAM SPAM SPAMPermission

0 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMno permission
1 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMexecute
2 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMwrite only
3 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMwrite and execute
4 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMread only
5 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMread and execute
6 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMread and write
7 SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAM SPAMread, write, execute


What about the users, you ask? Instead of using a number of user types, the absolute setting system uses the octal number placement. For example the command:


chmod 012 filename


means:
the user has no permissions (0)
the group has execute permission (1)
other has write-only permission (2)


The order is always the same. The first number will always be the user, the second will be the group, and the final number is other. You must list all three numbers when you use absolute setting syntax.