1

I messed up with some permission level on /var/www/ and /var/www/html/folders by running some random commands through putty.

Initially I want to add or edit some files in /var/www/html/ and I executed some commands which give me the permission to add or edit files through SFTP. But it causes a problem and I was unable to update or create any files through webserver apache.

After then I executed some random commands which gives apache to view and edit files under /var/www/html/ but I m not not able to view files from SFTP.

I have attached some screenshot of folder permission

My Configurtion

OS: Ubuntu 18.04
Provider: AWS
FTP Username: ubuntu

I logged in to SFTP through PPK files

Now I want to gain access through SFTP to /var/www/html/

enter image description here

enter image description here

3 Answers 3

0

You need to log in as a user with sudo permission, or as root. If the user does not have root permission, they have to respect the folder owner

And since the owner is apache, of course certain non sudo users can't access it

3
  • I am able to logged in as root through putty by command sudo su -. But I logged into FTP account through ubuntu user Feb 24, 2019 at 15:14
  • @PlanetHackers the user must be sudo, or the root user
    – unixandria
    Feb 24, 2019 at 21:14
  • I know that sudo su - do the same Feb 25, 2019 at 15:57
0

I manage with similar case in that way:

groupadd web
groupmems -g web -a myuser
chown -R .web /var/www/html/
chmod -R g+w /var/www/html/
mkdir ~myuser/web
mount --bind /var/www/html/ ~myuser/web

Explanation: create group for myuser (and others) and mount point in his mode directory. Then mount --bind apache dir.

You have to add mount to the start script.

Now you will have access to apache dir from your home.

0

After 2 year I had chance to answer to my own question. So if someone facing same problem they can follow this answer

There might be two simplest possible approach:

  1. Assign all files & Folders owership to Webserver. In most case its www-data if apache/nginx is installed. If not find webserver user first #Ref.

    sudo chown -R www-data:www-data /var/www/html/

This will assign all files & folders ownership to www-data user & www-data user group. Check chown command reference

  1. And add the FTP/SFTP username to webserver group.

    sudo usermod -a -G www-data ubuntu

This will add ubuntu user to webserver group www-data. Check usermod command for reference`

  1. Add permission to all files & folders

    sudo chmod -R 775 /var/www

This will add permission to all files/folders in /var/www/ as per follows

R = 4 (Octal Value for read permission)
W = 2 (Octal value for Write Permission)
X = 1 (Octal value for execute permission)

Owner: 4+2+1 = 7 (Read/Write/Execute)
Group: 4+2+1 = 7 (Read/Write/Execute)
Others: 4+1 = 5 (Read/Execute)

Through this way Owner & group has read, write and execute permissions. User logged in from ftp/sftp is already added on webserver group in second step. So Webserver & FTP user would both will be able add/edit files.

2
  • Cool but I consider it a bad idea to directly alter a website; the better approach would be to have each user log onto a separate partition and have a cron job create a timestamped backup of the files uploaded and then have the files moved to /var/www/ Next: chmod 777 is ALWAYS terrible. 750 is more than enough if you use "user"; if you use a "group" with diff users 770 is enough.
    – Rinzwind
    Jul 10, 2022 at 19:52
  • I agree with 777 & 750 permission. For access management ot would be better to use git and different branch. Jul 11, 2022 at 23:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .