Jump to content

Messed up permissions using SFTP/Filezilla/Ubuntu/rmdir


waslsdnowlds

Recommended Posts

I've written some code to remove a directory using rmdir. Yes, the line above it removes the files inside that folder. I know the code works on different servers.

 

I believe the issue lies in how I set up my Ubuntu server (via AWS). To sftp I use the user ubuntu to put all my files into var/www/html. Then in mysql, I'm using root for everything including connecting to the database via root.

 

When my code attempts to remove a directory, it cannot due to permissions. I know this because I have to set the permissions to 777 to get the code to remove it.

 

Then when anything new is placed into the var/www/html (which ive also chmod to 777), I still need to chmod anything new placed into that directory.

 

Hope this makes sense.

 

Where do I go from here? I don't understand why my code cannot delete files within the var/www/html without me having to ssh and chmod whatever needs to be deleted. Perhaps, it's because Ubuntu user dropped them via sftp in instead of root?

Link to comment
Share on other sites

It can't because permissions. Understand permissions and you'll understand why you can't do things.

 

You say "when anything new is placed" - how is that done? Are you talking about stuff uploaded through FTP or about files and directories created by PHP?

Link to comment
Share on other sites

It can't because permissions. Understand permissions and you'll understand why you can't do things.

 

You say "when anything new is placed" - how is that done? Are you talking about stuff uploaded through FTP or about files and directories created by PHP?

 

When anything new is placed in the var/www/html directory via sftp using the ubuntu user.

Link to comment
Share on other sites

0777 should allow any user to do anything to the directory, including creating new files and deleting existing ones. Modifying the files themselves requires the appropriate ?+rw or better on the files themselves.

 

But you should not have to do this. What are you uploading, into exactly which directories, and why do they need to be deleted by PHP and not you?

Link to comment
Share on other sites

0777 should allow any user to do anything to the directory, including creating new files and deleting existing ones. Modifying the files themselves requires the appropriate ?+rw or better on the files themselves.

 

But you should not have to do this. What are you uploading, into exactly which directories, and why do they need to be deleted by PHP and not you?

 

I have an installation that needs to delete the install folder after install is completed. It deletes all files in the directory, then removes the directory.

 

So, what I've done so far is the following below.

sudo groupadd -g 5252 website
sudo usermod -g website www-data
sudo usermod -g website ubuntu
sudo usermod -g website root

sudo chgrp website var/www/
sudo chgrp website var/www/html/

sudo chmod 775 var/www/ -R
sudo chmod 775 var/www/html -R

sudo chmod g+s var/www/ -R
sudo chmod g+s var/www/html -R

sudo setfacl -dm g::rwX var/www/
sudo setfacl -dm g::rwX var/www/html

sudo setfacl -dm o::rX var/www/
sudo setfacl -dm o::rX var/www/html

Yet, all my files upload via FTP have a rw-rw-rw- permission. The folders have a drwxrwsrwx. So, weird.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.