Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using pscp and getting permission denied

Tags:

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?

like image 943
Espen Avatar asked Dec 21 '10 20:12

Espen


People also ask

How do I fix SCP permissions denied?

Change the directory The root directory in Windows doesn't let users save data, which can cause the SCP permission denied error. Instead, store data in a folder or somewhere else. You can specify the path to your home directory using.

How do I give permission to SCP?

You need to use the -r for recursive copy and make sure you have write permissions to the destination. Try doing a touch /path/to/local/destination/file and see if you get permission denied. If so then use sudo scp to copy the files.

How do I fix permissions denied in Linux?

To fix the permission denied error in Linux, one needs to change the file permission of the script. Use the “chmod” (change mode) command for this purpose.


2 Answers

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.

like image 123
RoelAdriaans Avatar answered Sep 20 '22 23:09

RoelAdriaans


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

like image 37
dejris Avatar answered Sep 22 '22 23:09

dejris