Настройка sudo в linux

Как установить в WordPress права на папки и файлы

В предыдущих статьях мы уже обсуждали способы редактирования файлов. Обычно я использую для этого файловый менеджер своего хостинга. У него приятный и удобный интерфейс и не нужно запускать отдельных программ и создавать соединение, все делается через окно браузера.

Чтобы установить атрибуты файлу, выделите его, щелкните правой кнопкой мыши – «Изменить атрибуты». В открывшемся окне отметьте нужные галочками или впишите цифрами. Какие именно права каким файлам назначать мы рассмотрим чуть позже.

«Применить рекурсивно»
— очень нужны параметр, позволяет в один клик установить нужные атрибуты не только папке, но и всем ее подпапкам и файлам.

Changing Access Permissions with chmod

File access permissions can be modified via the chmod command. The name chmod is short for “change mode”.

We can use two ways of calling chmod, symbolic or octal notation.

5.1. Symbolic Notation

In symbolic notation, we provide chmod with a comma-separated string using references for user (u), group (g) and others (o).

Let’s remember the access permissions of document.docx: -rw-rw-r–

We can set these same permissions with the symbolic notation:

It’s also possible to add permissions incrementally. For example, we can add write permissions for others:

Or similarly, we can take away write access for the group by calling:

We should note that incremental changes only operate on the group and flag specified, leaving the other access permissions as they were.

We can combine references to set permissions all at once. To make the document read-only for group and others, we can use:

There even is a shorthand notation – a – to set permissions for all references. For example, we can make our document read-only for every user and group with:

5.2. Octal Notation

A widely used, often shorter, form of calling chmod is by use of the octal notation. This is a combination of three numbers by which we can represent all combinations of access rights.

The following table shows the equivalent octal and symbolic notations:

Each possible combination of access permissions can be written as a binary number, with 1 and 0 meaning the permission is turned on or off. These binary numbers represent digits 0 to 7, the 8 digits that make up the octal numeral system.

Going back to the example of the previous section, the equivalent of:

in octal notation is:

We should also note that in octal notation, it is not possible to add permissions incrementally.

Syntax

chown [-c|--changes] [-v|--verbose] [-f|--silent|--quiet] [--dereference]
      [-h|--no-dereference] [--preserve-root]
      [--from=currentownercurrentgroup] [--no-preserve-root]
      [-R|--recursive] [--preserve-root] [-H] [-L] [-P]
      {new-owner|--reference=ref-file} file ...
chown --help
chown --version

Specifying the new owner

New ownership of file is specified by the argument new-owner, which takes this general form:

[user[group]]

Specifically, there are five ways to format new-owner:

new-owner form Description
user The name of the user to own the file. In this form, the colon («») and the group is omitted. The owning group is not altered.
usergroup The user and group to own the file, separated by a colon, with no spaces in between.
group The group to own the file. In this form, user is omitted, and the group must be preceded by a colon.
user If group is omitted, but a colon follows user, the owner is changed to user, and the owning group is changed to the login group of user.
Specifying a colon with no user or group is accepted, but ownership will not be changed. This form does not cause an error, but changes nothing.

Notes on usage

  • user and group can be specified by name or by number.
  • Only root can change the owner of a file. The owner cannot transfer ownership, unless the owner is root, or uses sudo to run the command.
  • The owning group of a file can be changed by the file’s owner, if the owner belongs to that group. The owning group of a file can be changed, by root, to any group. Members of the owning group other than the owner cannot change the file’s owning group.
  • The owning group can also be changed by using the chgrp command. chgrp and chown use the same system call, and are functionally identical.
  • Certain miscellaneous file operations can be performed only by the owner or root. For instance, only owner or root can manually change a file’s «atime» or «mtime» (access time or modification time) using the touch command.
  • Because of these restrictions, you will almost always want to run chown as root, or with sudo.

Особенности

Значениями по умолчанию являются:

  • для файлов: 644 (-rw-r--r--)
  • для каталогов: 755 (drwxr-xr-x)

Значения разные для файлов и каталогов потому, что флаг «выполнения» по-разному действует на файлы и каталоги. Для обычных файлов «выполнение» означает открытие файлов, для исполняемых файлов — их запуск, а для каталогов — просмотр содержимого.

Например, можно сделать из командной строки:

Следующая команда выполнит рекурсивное применение правил для всех файлов в каталоге «/home/test», а также для всех файлов во всех подкаталогах:

# find /home/test -type f -exec chmod 644 {} \;

Следующая команда выполнит рекурсивное применение правил для всех каталогов в каталоге «/home/test», а также для всех каталогов во всех подкаталогах:

# find /home/test -type d -exec chmod 755 {} \;

Того же результата можно добиться и без использования find (обратите внимание на заглавную X):

# chmod -R go=rX,u=rwX /home/test

OPTIONS

Tag Description
-c—changes Verbosely describe the action for each File whose ownership actually changes.
—dereference Do not act on symbolic links themselves but rather on what they point to.
-f—silent—quiet Do not print error messages about files whose ownership cannot be changed.
-h—no-dereference Act on symbolic links themselves instead of what they point to. This is the default. This mode relies on the ‘lchown’ system call. On systems that do not provide the ‘lchown’ system call, ‘chown’ fails when a file specified on the command line is a symbolic link. By default, no diagnostic is issued for symbolic links encountered during a recursive traversal, but see ‘—verbose’.
—reference=FILE Use the user and group of the reference FILE instead of an explicit NewOwner value.
-R—recursive Recursively change ownership of directories and their contents.
-v—verbose Verbosely describe the action (or non-action) taken for every FILE. If a symbolic link is encountered during a recursive traversal on a system without the ‘lchown’ system call, and ‘—no-dereference’ is in effect, then issue a diagnostic saying neither the symbolic link nor its referent is being changed.
Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

Adblock
detector