Get the most out of your Centmin Mod LEMP stack
Become a Member

Properly give a permission to accidentally removed vhost's public folder?

Discussion in 'Install & Upgrades or Pre-Install Questions' started by trxerz, Jul 5, 2016.

  1. trxerz

    trxerz Member

    66
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    8:05 PM
    Hi,
    I accidentally removed public folder in /home/nginx/domains.com/ . So, I make a new directory with mkdir command. However, the new public folder permission is different from the other folder, it has drwxr-sr-x while the other has drwxr-s---.

    When I try to change the permission manually with the following command
    Code:
    chmod 740 /home/nginx/domains/domain.com/public/
    It changes to drwsr-S--- with big/capitalize S not small s.

    Can anyone tell me how to properly chmod it?
     
  2. eva2000

    eva2000 Administrator Staff Member

    30,898
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,403
    Local Time:
    6:05 AM
    Nginx 1.13.x
    MariaDB 5.5
    should fix it
    Code (Text):
    chmod 750 /home/nginx/domains/domain.com/public
    chown nginx:nginx /home/nginx/domains/domain.com/public
    
     
  3. trxerz

    trxerz Member

    66
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    8:05 PM
    Hi, thanks Eva...
    I've restore whole wordpress file from dropbox, but the the whole file permission changed to -rw-rw-rw- and drwxr-sr-x for folder, is it OK?
     
  4. eva2000

    eva2000 Administrator Staff Member

    30,898
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,403
    Local Time:
    6:05 AM
    Nginx 1.13.x
    MariaDB 5.5
    compressed file or extracted folders ?

    use ls and stat commands to show us what you have i.e. for public directory and a file at public/file.txt
    Code (Text):
    ls -lah /home/nginx/domains/domain.com
    ls -lah /home/nginx/domains/domain.com/public
    stat /home/nginx/domains/domain.com/public
    stat /home/nginx/domains/domain.com/public/file.txt

    Might want to use CODE tags for code How to use forum BBCODE code tags :)

    FYI normal permissions are 644 for files and 755 for directories or if you app/setup can handle 640 files and 750 directories
     
    Last edited: Jul 5, 2016
  5. trxerz

    trxerz Member

    66
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    8:05 PM
    Yes, in Dropbox the backup was compressed then I unzip it via SSH.

    Code:
    ls -lah /home/nginx/domains/domain.com
    total 24K
    drwxr-s--- 6 nginx nginx 4.0K Jul  5 10:12 .
    drwxr-s--- 6 nginx nginx 4.0K Jul  5 10:12 ..
    drwxr-s--- 2 nginx nginx 4.0K Jul  5 10:12 backup
    drwxr-s--- 2 nginx nginx 4.0K Jul  5 10:12 log
    drwxr-s--- 2 nginx nginx 4.0K Jul  5 10:12 private
    drwxr-s--- 5 nginx nginx 4.0K Jul  5 10:30 public
    
    ls -lah /home/nginx/domains/domain.com/public
    drwxr-s---  5 nginx nginx 4.0K Jul  5 10:30 .
    drwxr-s---  6 nginx nginx 4.0K Jul  5 10:12 ..
    -rw-r-----  1 nginx nginx 1.4K Jul  5 10:12 index.html
    -rw-rw-rw-  1 nginx nginx  418 Jul  4 15:36 index.php
    
    stat /home/nginx/domains/domain.com/public
      File: `/home/nginx/domains/domain.com/public'
      Size: 4096         Blocks: 8          IO Block: 4096   directory
    Device: fc01h/64513d    Inode: 391772      Links: 5
    Access: (2750/drwxr-s---)  Uid: (  500/   nginx)   Gid: (  500/   nginx)
    Access: 2016-07-05 10:32:58.025508414 +0000
    Modify: 2016-07-05 10:30:56.413155579 +0000
    Change: 2016-07-05 10:30:56.413155579 +0000
    
    stat /home/nginx/domains/domain.com/public/index.php
      File: `/home/nginx/domains/domain.com/public/index.php'
      Size: 418           Blocks: 8          IO Block: 4096   regular file
    Device: fc01h/64513d    Inode: 391794      Links: 1
    Access: (0666/-rw-rw-rw-)  Uid: (  500/   nginx)   Gid: (  500/   nginx)
    Access: 2016-07-04 15:36:48.000000000 +0000
    Modify: 2016-07-04 15:36:48.000000000 +0000
    Change: 2016-07-05 10:16:14.101509559 +0000
    
     
  6. eva2000

    eva2000 Administrator Staff Member

    30,898
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,403
    Local Time:
    6:05 AM
    Nginx 1.13.x
    MariaDB 5.5
    files should be 644 or 640 and directories 755 or 750
    Code (Text):
    find /home/nginx/domains/domain.com/public/ -type d -exec chmod -R 755 {} \;
    find /home/nginx/domains/domain.com/public/ -type f -exec chmod -R 644 {} \;

    or
    Code (Text):
    find /home/nginx/domains/domain.com/public/ -type d -exec chmod -R 750 {} \;
    find /home/nginx/domains/domain.com/public/ -type f -exec chmod -R 640 {} \;

    this finds all directories and chmod to 755 or 750 and all files found chmod to 644 or 640

    Backup First !



    backup permissions first before running above commands so you can restore if you stuff up

    backup all directory and file permissions inclusive and under public to file at /home/nginx/domains/domain.com/backup_perm/public-dir-permission-backup.acl
    Code (Text):
    mkdir /home/nginx/domains/domain.com/backup_perm
    cd /home/nginx/domains/domain.com/backup_perm
    getfacl -R --absolute-names /home/nginx/domains/domain.com/public > /home/nginx/domains/domain.com/backup_perm/public-dir-permission-backup.acl
    

    restore all directory and file permissions saved at /home/nginx/domains/domain.com/backup_perm/public-dir-permission-backup.acl
    Code (Text):
    setfacl --restore=/home/nginx/domains/domain.com/backup_perm/public-dir-permission-backup.acl
    
     
  7. trxerz

    trxerz Member

    66
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    8:05 PM
    bash: getfacl: command not found
    Should I install first? my VPS is Centos 6
    Code:
    yum install acl
     
  8. trxerz

    trxerz Member

    66
    5
    8
    Jun 25, 2015
    Ratings:
    +7
    Local Time:
    8:05 PM
    Code:
    find /home/nginx/domains/domain.com/public/ -type f -exec chmod -R 644 {} \;
    Went ok,

    Code:
    -rw-r--r--  1 nginx nginx     5032 Jul  4 15:36 wp-activate.php
    drwxr-sr-x  9 nginx nginx     4096 Jul  5 10:15 wp-admin
    But,
    Code:
    find /home/nginx/domains/domain.com/public/ -type d -exec chmod -R 755 {} \;
    is not good.
    Code:
    -rwxr-xr-x  1 nginx nginx     5032 Jul  4 15:36 wp-activate.php
    drwxr-sr-x  9 nginx nginx     4096 Jul  5 10:15 wp-admin
     
  9. eva2000

    eva2000 Administrator Staff Member

    30,898
    6,908
    113
    May 24, 2014
    Brisbane, Australia
    Ratings:
    +10,403
    Local Time:
    6:05 AM
    Nginx 1.13.x
    MariaDB 5.5
    yup
    should of worked - did you run getfacl and setfacl after the chmod ? setfacl would of restored your old incorrect permissions so only need to run setfacl restore if you want to revert those permissions to ones prior to find/chmod