0

I gave permission to the user "www-data" in the entire contents of the "/var/www" folder.

However, I work with the root user with a private key via SFTP, and whenever I modify a file, the owner of the file becomes root.

How to edit the files and keep the "www-data" as owner?

  • 2
    I do not know the correct answer, but I judge it has something with SUID SGID and sticky bit. You can get more than 100 hits if looking for that keywords. – schweik Nov 16 '18 at 22:31
  • @roaima Thanks for the comment, you opened my mind. I really had not thought that when a file is modified it was deleted and a new file was created. So I went to check if the creation date was changed, and found that there is no date of creation of a file on linux systems. What I have to do is change the owner of the file again every time I modify it, so nginx will work normally. – Marcelo Nov 17 '18 at 22:40
2

With sftp you don't modify a file in place, you copy it to your machine, modify it, and then replace it with the new version, which necessarily then is owned by the user you connected as. Use other means of editing. sshfs might be an option; use a sensible editor like vi ;) through ssh.

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.