Chmod Protection:
Chmod (abbreviation from the English language to change mode, change mode) is a command of Unix systems and Unix-like systems, and more generally of POSIX systems to change the permissions of files and directories.
Chmod is also the name of a system call, defined by the POSIX standard, which change the permissions of a file or directory. In fact, the chmod command by invoking the same name system call.
The chmod command appeared for the first time in the first version of Unix from AT & T and is still used in Unix and Unix-like machines.
Chmod
The general syntax of chmod is:
chmod [options] [-] mode file1 [file2 ...]
Mode parameter indicates the changes to be applied to permits.
The double hyphen – (optional) indicates that the following parameters are not considered options.
Among the main options are:
R
Change the permissions of directories recursively listed and their content.
-h
For BSD-derived systems (such as FreeBSD, NetBSD and OpenBSD, and even Mac OS X), where you can also assign permissions to symbolic links, this option specifies precisely to change the permissions of symbolic links instead of those files referenced.
Examples:
Symbolic representation
* Chmod ‘u = rwx “,” g = rx “,” o = x “filename
* Chmod “+ o = rx” filename
* Chmod “= u + rwx”, “go =-” filename
* Chmod “+ u = rws”, “go =-” filename
For the meaning of S also see other Unix permissions.
Octal representation
* Chmod 734 filename
Mode
The mode is a string that indicates how to set or change the permissions of files and directories specified. Can be expressed as an octal number, or in symbolic form.
Octal mode
It is a number composed of one to four octal digits (eg 640 or 4755), according to the octal representation of permissions, which indicates permission to be given directly to the file without taking into account those already present.
For example, a 755 permission set read, write and execute (7) to the owner (first digit), and read and execute (the two 5) per group (second figure) and other (third digit).
Symbolic mode
It is a series of one or more text values separated by commas.
Each value is in turn composed of three parts:
* A first part consists of zero or more letters that select the classes (owner, group, others) for which you want to modify the permission:
ou – select the class concerning the owner
or g – select the class for the group
oo – select the class relative to other users
or no letter or – selects all classes
* A second part consists of a single character indicating whether permission should be added, removed or set to the selected classes:
o + – adds the specified permissions to the selected classes, does not remove permissions already granted but not specified
o = – set the permissions specified in the classes selected, removes any permissions already granted but not specified
o – - removes the permissions specified by the selected classes
* A third part consists of zero or more letters (e.g., r, w, x, s, t) according to the symbolic representation of permits give the permissions to add, remove or set.
Examples of rules are expressed in a symbolic “ugo = rwx”, “u = rwx, go = r”, “+ x”.
Examples of the
* 0755 – sets read, write and execute for the owner, and read and execute for group and others (common for directories and executable files);
* 0700 – sets read, write and execute for the owner, no permissions for group and others (common for directories private);
* 0600 – Set read and write to the owner and no permissions for group and others (common for data files);
* 0640 – Set read and write for owner, read only for the group and no permissions for others (the common data files to be shared);
* + R – adds read permission for the owner for the group and for others. Not remove other permits already present;
*-X – remove execute permission to owner, group and others. Not remove other permits already present;
* Ug = rx – sets the read and execute permission to the owner, remove any existing writable, does not alter the permissions for others;
* U = rx, g = – sets the read and execute permission to the owner, by removing any write permission already exists, remove all existing permissions for the group and for others.
The system call chmod
System call chmod is declared in the header file sys / stat.h:
# include <sys/stat.h>
int chmod (const char * path, mode_t mode);
Type mode_t is a matte (usually a type integer) that represents the access permissions.
The path parameter is the name of the file or directories that change the permissions.
The mode parameter indicates the permissions for the file or directory.
Return value
The return value is 0 on success. If an error is -1, and the variable errno indicates the specific error.
Study: From Wikipedia, the free encyclopedia. The text is available under the Creative Commons.
~ No related posts.












