28

I'm using pscp to transfer files to a virtual ubuntu server using this command:

pscp test.php user@server:/var/www/test.php

and I get the error permission denied. If I try to transfer to the folder /home/user/ I have no problems.

I guess this has to do with that the user I'm using doesn't have access to the folder /var/www/. When I use SSH I have to use sudo to get access to the /var/www/ path - and I do.

Is it possible to specify that pscp should "sudo" transfers to the server so I can get access to the /var/www/ path and actually be able to transfer files to this folder?

Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
Espen
  • 3,607
  • 11
  • 48
  • 75
  • 1
    Sent the file to `/home/user/test.php`. Then use `plink` or another SSH client to move the file there using sudo if needed. I think it is better than playing with permissions and breaking everything. – Akira Yamamoto Aug 02 '17 at 01:37
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Server Fault](http://serverfault.com/) or [Webmaster Stack Exchange](http://webmasters.stackexchange.com/) would be a better place to ask. – jww Aug 18 '18 at 12:21

3 Answers3

31

If you own the server:

Add yourself to the www-data group:

sudo usermod -a -G www-data <username>

And set the right permissions:

sudo chown -R www-data:www-data /var/www/
sudo chmod -R 0775 /var/www/

This should do the trick.

PA.
  • 28,486
  • 9
  • 71
  • 95
RoelAdriaans
  • 763
  • 7
  • 16
  • 2
    I would make note of the current owners of some of the folders as performing the above broke one of my sites. I'm aware it's my own fault, however I had to change the ownership back because I'd configured ruby/rails/rvm to use a separate set of user names. – Antony Koch Jan 06 '12 at 09:56
  • Should've read this comment before diving in and running those commands. Totally screwed our EC2 instance at work, and now the dev server is out for a few hours. :( Be careful using `sudo`!! – Jonathan Mar 31 '14 at 03:09
  • 4
    `sudo usermod -a -G www-data ` worked for me – Akira Yamamoto Aug 02 '17 at 01:25
  • 5
    "-a" needs to be before "-G" otherwise I got a "group not found" error – TreeAndLeaf Nov 23 '17 at 23:38
10

Beware of the following that when you write

sudo usermod -G www-data <username>

The option -G will make the specified user () a member of the particular group(s) that are specified. So the above statement will make the user a part of group www-data BUT will remove the user from any other group that the user belongs to. To avoid this you must either add the option -a or specify all the current groups that you want the user to be a part of. I accidently took the user "administrator" out of the sudo group because I didn't know this. So if you want the specified user to keep it's current group membership then write the following command.

sudo usermod -G -a www-data <username>

For more info regarding the usermod command, visit:

Ubuntu manpages - usermod

dejris
  • 101
  • 1
  • 2
2

I had the same error "pscp: unable to open YourFilePath: permission denied",

check the ownership of the file you are trying to overwrite, you will get this error if you can't overwrite it,

If you don't have control over the remote file, just simply try to rename the file you are trying to move.