i'm hosting some websites in same server, but this server doesn't come with root login and password, i only have access to ubuntu user and password, and when i'm logged in, i can use the command sudo su - to turn into a root user.

but using i'm using sftp to edit the files of the websites, and i can only log in using ubuntu user, i'm not able to use root user.

the problem is that i'm having permission denied when i try to edit some files. the files must have permission 644 and the folders must have permission set to 755 if the permissions aren't like this my application doesn't run.

so i have to choose, between editing the files and stop the application, or run the application and get permission denied when i edit the files. i can't do both at the same time, it's boring.

so i gotta use this command to edit anything i want, and the application stops, because the permission of the files goes to 674 and permission of the folders goes to 775:

sudo usermod -a -G ubuntu www-data
sudo setfacl -R -m u:ubuntu:rwx /var/www/

and when i edited everything i gotta use this command, to the permissions go back to 644 in files, and 755 in folders and the application goes back to normal.

find /var/www -type d -exec chmod 755 {} \;
find /var/www -type f -exec chmod 644 {} \;

so how can i fix this? i want to do both at the same time.

  • Are you saying that, when you edit the files, the permissions change? I'm a bit confused as to why the permissions change when you edit the files. – msb Aug 6 '20 at 22:54
  • yes, when i use that command to be able to edit the files, the permission of the file goes to 674 and the permission of the folders goes to 775. – Felipe S. Aug 6 '20 at 22:58
  • I see. And how do you edit the files? you said you're using sftp? but sftp is a tool for transfering files over ssh (ssl), not an editor. – msb Aug 6 '20 at 23:03
  • Look: i.imgur.com/xjEyPzH.png, i'm using filezilla on sftp, i choose the file i want to edit, and i click edit, and i edit with the editor on my computer and i save, it saves automatically to the server. – Felipe S. Aug 6 '20 at 23:09
  • Ok, your screenshot shows that you are using filezilla to transfer the files over sftp. I assume you're editing the files locally in your computer (meaning, not directly in the machine that has the files and hosts the websites), and I assume you're editing the files by opening them directly in filezilla (lthough how you edit the file is probably irrelevant). Filezilla could be the one setting the file permissions, when it uploads the modified file back to the server. – msb Aug 6 '20 at 23:18

You are using the user ubuntu which doesn't have permission to create/edit files in /var/www. So you're giving it permissions, uploading the new files, and removing permissions. You need to remove permissions back because the server will give you permission denied if your files have too wide permissions.

You have 3 alternatives:

  1. change the server settings to run files with wider permissions. This might be a security problem.
  2. move the website to the 'ubuntu' user dir, and make a link in /var/www. You might need to change further settings for this to work (see FollowSymLinks), but once it's set up all files will have proper permissions and ubuntu will be the owner.
  3. connect to the server with the user that owns the files in /var/www/[project]/public_html. You'll need to allow that user to connect, which might be a security problem.

P.S.: you don't need to run the usermod command multiple times. Once the user is in the group, it's in the group, there shouldn't be any process removing it from the group.

  • okay, i'm gonna try to do it right now, will be back to say if it worked. – Felipe S. Aug 6 '20 at 23:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.