Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I saw several threads about having issues with unexpected file permissions after file upload. I tried their solutions with no luck, I have to raise the problem in my way.

I run Nginx as nobody:nogroup on Debian 6. I changed the root web folder /usr/share/nginx/html to nobody:nogroup. Now I use WinSCP to upload file to the machine , but I use root account. If I create a new directory or update a new file, the ownership would be root:root. I am new to Linux world, I currently open a shell to change ownership of wwwroot after I have uploaded something to my server.

What is the best practice to upload file as root, but keep files and directories nobody:nogroup? Shall I set a password to account nobody and use this account to upload files?

share|improve this question
    
It's somewhat dangerous to login as root, even over a secure connection. Many of the attacks on SSH/SCP have been ways to trick the file transfer client or server into using no encryption. It would be better to create a special account just for uploading, with as restrictive permissions as possible. –  Snowbody Jan 2 at 20:07

2 Answers 2

up vote 3 down vote accepted

You can change group of the upload directory chgrp nogroup UPLOAD_DIR and set group ID on it chmod g+s UPLOAD_DIR - files created in this directory will have group nogroup. You can set default rights using umask 002 (perhaps when starting WinSCP session?) and all files will have rw rights for group. The owner will still be root, but the Nginx process should be able to manage files through nogroup membership.

share|improve this answer

I do not know of any automatic solution for new files. Though, if you find that you need to keep changing the ownership manually, you can make use of various WinSCP features to make your life easier.

WinSCP allows changing ownership in the GUI (though if you use OpenSSH server, you have to use numeric GID/UID):
http://winscp.net/eng/docs/ui_properties

Alternatively, you can execute the chown command from WinSCP itself to avoid opening separate shell terminal. You can even setup custom command chown nobody:nogroup . in WinSCP to speed this up:
http://winscp.net/eng/docs/custom_command

You can even assign keyboard shortcut to the command to make this even easier:

enter image description here

For updating files, make sure you disable transfer setting Transfer to temporary filename as this effectively creates new file for every transfer (by default for files over 100 KiB only). When disabled, WinSCP only updates an existing file, so the ownership is preserved.
http://winscp.net/eng/docs/resume#automatic
http://winscp.net/eng/docs/ui_pref_resume

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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