Chmod: Difference between revisions

From Psygen Wiki
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 32: Line 32:
      
      
700 - (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.
700 - (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.
=== Break-down ===
Each place of the three digits represents the owner, the group, and other.
<pre>
  0 - No permission
* 1 - execute
* 2 - write
  3 - write and execute
* 4 - read
  5 - read and execute
  6 - read and write
  7 - read, write, and execute
</pre>
You add the starred items above to get the higher numbers.
'''Example:'''
<code>chmod 644 file.txt</code> This changes the permissions on file.txt so that the owner has read and write permissions (6), the group has read permission (4), and other has read permission (4)


== Symbolic (letters) ==
== Symbolic (letters) ==
Line 47: Line 70:
<code>chmod og=rw index.html</code> Sets the group and other permissions at the same time to Read and Write.
<code>chmod og=rw index.html</code> Sets the group and other permissions at the same time to Read and Write.


'''Who:'''
=== Who: ===


<pre>
Letter Meaning
Letter Meaning
   u  The user who owns the file (this means “you.”)
   u  The user who owns the file (this means “you.”)
Line 54: Line 78:
   o  The other users
   o  The other users
   a  all of the above (an abbreviation for ugo)
   a  all of the above (an abbreviation for ugo)
</pre>


'''Permissions:'''
=== Permissions: ===


  r  Permission to read the file.
<pre>
  r  Permission to read the file.
   w  Permission to write (or delete) the file.
   w  Permission to write (or delete) the file.
   x  Permission to execute the file, or, in the case of a directory, search it.
   x  Permission to execute the file, or, in the case of a directory, search it.
</pre>
=== Adding and Removing Permissions===
You can add and subtract permissions using + and -
<pre>
Operator  Meaning
  =      assign permissions
  +      add permissions
  -      remove permissions
</pre>
'''Examples:'''
<code>chmod u+x</code> For '''you''', add '''execute''' permission.
<code>chmod go-w support</code> For '''group''' and '''other''', subtract (remove) '''write''' permission.
<code>chmod a+wx calcs.txt</code> For all (owner, group, and other) add '''write''' and '''execute''' permissions.
<code>chmod ug=rw logo.jpg</code> Assign the owner and group read and write permissions.
== Reset web directory and file permissions ==
To recursively reset permissions for directories and files:
For directories (current directory and below):<br />
<code>find `pwd` -type d -exec chmod 755 {} \;</code>
For files (current directory and below):<br />
<code>find `pwd` -type f -exec chmod 644 {} \;</code>


== References ==
== References ==

Latest revision as of 18:51, 19 April 2017

chmod manages file and directory permissions

Usage: chmod permissions filename

Octal

Example:

chmod 644 myfile.txt

Common Settings

Files:

777 - (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.

755 - (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.

700 - (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.

666 - (rw-rw-rw-) All users may read and write the file.

644 - (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.

600 - (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.

Directories:

777 - (rwxrwxrwx) No restrictions on permissions. Anybody may list files, create new files in the directory and delete files in the directory. Generally not a good setting.

755 - (rwxr-xr-x) The directory owner has full access. All others may list the directory, but cannot create files nor delete them. This setting is common for directories that you wish to share with other users.

700 - (rwx------) The directory owner has full access. Nobody else has any rights. This setting is useful for directories that only the owner may use and must be kept private from others.


Break-down

Each place of the three digits represents the owner, the group, and other.

  0 - No permission
* 1 - execute
* 2 - write
  3 - write and execute
* 4 - read
  5 - read and execute
  6 - read and write
  7 - read, write, and execute

You add the starred items above to get the higher numbers.

Example:

chmod 644 file.txt This changes the permissions on file.txt so that the owner has read and write permissions (6), the group has read permission (4), and other has read permission (4)


Symbolic (letters)

chmod who=permissions filename

Examples:

chmod o=r mybackup.tgz Change the permissions for Other to Read-only

chmod g= jdoe.txt Remove group permissions (same as chmod g=--- jdow.txt )

You can also adjust multiple permissions at once:

chmod og=rw index.html Sets the group and other permissions at the same time to Read and Write.

Who:

Letter	Meaning
  u   	The user who owns the file (this means “you.”)
  g   	The group the file belongs to.
  o   	The other users
  a   	all of the above (an abbreviation for ugo)

Permissions:

  r   	Permission to read the file.
  w   	Permission to write (or delete) the file.
  x   	Permission to execute the file, or, in the case of a directory, search it.

Adding and Removing Permissions

You can add and subtract permissions using + and -

Operator  Meaning
   =      assign permissions
   +      add permissions
   -      remove permissions

Examples:

chmod u+x For you, add execute permission.

chmod go-w support For group and other, subtract (remove) write permission.

chmod a+wx calcs.txt For all (owner, group, and other) add write and execute permissions.

chmod ug=rw logo.jpg Assign the owner and group read and write permissions.


Reset web directory and file permissions

To recursively reset permissions for directories and files:

For directories (current directory and below):
find `pwd` -type d -exec chmod 755 {} \;

For files (current directory and below):
find `pwd` -type f -exec chmod 644 {} \;

References

  1. chmod man page
  2. catcode chmod tutorial