WinSCP problem with modifying files that belong to www-data while logged in as my_user

Posted on 2014-08-07
Last Modified: 2014-08-07
Hi all,

I have a Ubuntu 14 x64 server and I login to it using Putty and SSH key so I don't use the password.
I have WinSCP installed that gives me ftp access to the site using my private key.

My sites are all owned by www-data and my user is called "lupocatttivo".
In putty I use the sudo commando to execute everything and it all works.
However in WinSCP when I try to modify or delete any file that is not my property,
I get this error:
Permission denied.
Error code: 3
Error message from server: Permission denied

Open in new window

Is there anyway I could set WinSCP to allow me to modify files owned by any user (just like I do with sudo in putty)?

Could anyone help me?

thanks in advance
Question by:badwolfff
    LVL 12

    Expert Comment

    The user you are logging in as need to have write permissions.  
    Assuming your WinSCP user is lupocatttivo -

    So if you have a file test.txt with www-data.lupocatttivo as the,
    Then set perms to 560 (the 6 is group, your lupocatttivo "group"), then you will be able to overwrite files as the lupocatttivo user/group.

    Keep in mind your php perms (www-data user) would need 5 (r,x) or 6(r,w) depending on what php needs to do with files via the www-data user.

    Author Comment

    I don't exactly follow you.
    I did this command on the whole joomla folder to own the files and give PHP the permission to write to filesystem:
    sudo chown -R www-data:www-data /my_joomla_folder/

    Do you mean to say that I should have done
    sudo chown -R www-data:lupocatttivo /my_joomla_folder/     ?

    If this is not so, then could you please explain more clearly? I use WINSCP and putty to login as lupocatttivo.
    The joomla folder and files are owned by www-data. I don't know how to get them owned by www-data.lupocatttivo as the

    thanks in advance
    LVL 12

    Accepted Solution

    Yes.  If your WinSCP user is lupocatttivo, then

    sudo chown -R www-data:lupocatttivo /my_joomla_folder/

    will make www-data the owner-user, and lupocatttivo the owner-group.  
    The other side of that is chmoding the permissions.  The important part here for your lupocatttivo user is the second number (560 or whatever), you understand the first number is the owner-users perms (www-data), second number is owner-group (lupocatttivo), and third is all others.
    4 = read (r--)
    5 = read, execute (r-x)
    6 = read, write (rw-)
    7 = read, write, exectute (rwx)

    So if www-data only needs r, lupocatttivo r,w, then
    sudo chmod -R 460 /my_joomla_folder/
    If you run into exectution problems, change the 4 to 5 (r,x)
    sudo chmod -R 560 /my_joomla_folder/

    Then, change the files www-data need to write to (via your other post) to
    sudo chmod 660 /my_joomla_folder/file_that_needs_writes.ext

    When you list files permissions (ls -a)
    Example -

    -r--rw---- 1 www-data   lupocatttivo    43 May  2 13:34 index.html

    www-data is user, lupocatttivo  is group.
    There are 10 dashes.  First one is a "d" if it's a directory, "-" if it's a file.
    In the example above -
    -     r--     rw-    ---  Is how it's broken down.  
    Its a file (-), then next 3 tics,  r-- means user www-data has read, no w, no x (execute).
    Next 3 after that (rw-) means the user lupocatttivo  has read, write, no x.
    Last 3 (---) mean "All other users not named" have NO permissions (no r, no w, no x)

    Root ALWAYS has rwx permissions unless you make it immutable.  But root can always immute / unimmute a file. Even if the owner/group is root.root and you set, say -r--------.  You will find root can still delete and do anything you want as root.  But don't get bogged down in immutable, it's rarely used.
    LVL 27

    Assisted Solution

    What user is your web server running as?  What group is it in?

    There should be a group www-data that the user www-data belongs to.  Add your account to the group.

    sudo useradd -G www-data lupocatttivo

    Then cd to your web site root:  (assuming default)
    cd /var/www

    Add write permissions to the group.
    chmod -R g+w .

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    You ever wonder how to backup Linux system files just like Windows System Restore?  Well you can use Timeshift in Linux to perform those similar action.  This tutorial will show you how to backup your system files and keep regular intervals. Note…
    Hello to you all, I hear of many people congratulate AWS (Amazon Web Services) on how easy it is to spin up and create new EC2 (Elastic Compute Cloud) instances, but then fail and struggle to connect to them using simple tools such as SSH (Secure…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now