How do I change file permissions via SSH? Печать

  • 0

Using the CHMOD command:

The letters u (for user), g (for group), and o (for other) are used with the letters r (for read permission, w (for write permission, and x (for execute permission) along with + (plus),- (minus), and = (equals) to alter permissions for a file. Some examples:

chmod u=rwx file.htm
chmod g-rwx config.inc.php
chmod o+rwx weblog.txt
chmod u=rwx,g-rwx,o=r other.htm

In the first example, the "user" group (u) is given read (r), write (w), and execute (x) permissions to the file "file.html". In the second, the "group" group (g) has read, write, and execute permissions subtracted for the file secret.txt; effectively making it inaccessible to that group. In the third example, the "other" group is given all permissions to the file, allowing that group (which includes the web server) to access and modify it fully. 

To use CHMOD with numerical permissions, a three digit number is formed. The first indicates the permissions that "user" should receive, the second indicates what "group" should receive, and the last indicates what "other" would receive. Some examples:

chmod 700 private.txt
chmod 755 normal.txt
chmod 707 forwebserver.txt

The first example gives all permissions to user (7), and no permissions to group or other (the zeroes). The second again gives all permissions to user, and gives read and execute permissions (5) to group and other. The last gives all permissions to user and other, but gives no permissions to group.

Помог ли вам данный ответ?

« Назад