20

I'm trying to scp some files from a server to my local machine but I either get a permission denied, or the server is copying the files to the server

ex:

scp username@host:/files/to/copy/from/\* /path/of/local/destination/ --> permission denied

scp username@host:/files/to/copy/from/\* ~ -->server copies to home directory on the server

scp username@host:/files/to/copy/from/\* ~/Desktop -->server creates a file called Desktop on server

I'm not sure what to do, this is on a Mac btw

  • 2
    Off-topic for SO; belongs on [su] – Jim Garrison Nov 04 '13 at 21:27
  • 1
    Do not paraphrase error messages. Copy/paste an exact transcript of the command entered and the response. What you have described makes no sense and since you paraphrased the exchange we can't tell what actually happened. – Jim Garrison Nov 04 '13 at 21:29

5 Answers5

18

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.

Chris Hinshaw
  • 6,967
  • 2
  • 39
  • 65
  • 8
    `make sure you have write permissions to the destination` D'oh! (slapping forehead) – Stack Underflow Oct 10 '18 at 19:11
  • @StackUnderflow Mine was a target permissions issue as well. I also added the -i flag with a path to my Mac's private key, but I am not sure if that was necessary. – King Holly Sep 18 '20 at 23:11
13

This can happen even if ssh works fine! The problem is File/Directory Permissions, for the most part! Using chmod 777 /path/dir/* gives write access to all the immediate children of /dir - including root files and directories. However, secondary files/directories are not affected by these permissions. Example: say i have this website: /var/www: index.php, css[mobile.css, global.css], js[init.js, fun.js], include[head.php, footer.php, body.php, fun.php]

To be able to overwrite fun.js: chmod 777 /var/www/js/*

kawerewagaba
  • 1,107
  • 2
  • 15
  • 21
2

I got the same issue. I use the username and password to scp files from windows to the username's account on ubuntu and get permision denied error. The reason is because one of the directory is owned by root. For example if the account is in /home/username then most likely /home is owned by root. If you change owner of /home then it may work. Try: sudo chown root: /folder

PhucLy
  • 43
  • 7
2

If there is a file with the same name as your source file in the destination directory, you need to remove it first. I encountered the issue like this.

Jepsenwan
  • 75
  • 2
  • 10
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/low-quality-posts/17326388) – FluffyKitten Sep 14 '17 at 05:19
  • @FluffyKitten Thanks for figuring out. I just wanted to provide an answer of what I have ever met earlier, which might be ignored in all provided answer. It likely was caused by scp not being able to overwrite the existing file in the same destination directory. – Jepsenwan Sep 14 '17 at 05:25
  • @FluffyKitten For clarification. In my case, I tried to download a file from the Internet with curl and root user. But it somehow had slow speed, so I cancelled it by Ctrl + c without removing the outstanding file. then I downloaded it on another host and later scp it to the previous host. It could not overwrite the root-downloaded file and merely gave permission denied. – Jepsenwan Sep 14 '17 at 05:36
0

I had the same problem.

Tried everything couldn't fix it, until I checked my ISP Gateway.

I work with a Zyxel gateway from my ISP and because that is far away from where I have another terminal I shoved a old Linksys DD-WRT flashed Router/Repeater in between. My host terminal that was connected to that Linksys was first connected to the Gateway with a DHCP table lock (I ordered the gateway to give the MAC from that terminal the same IP via DHCP). I did this because I first had a NAS server on that mac. Now I moved the terminal to another location and totally forgot the mac ip assignment.

So now i had a WIFI repeater connected to the Gateway, and the computer with the mac assigned was connected to that.

The problem now was that my Gateway thought it was the old NAS whilst it was the other terminal, and assigned the IP to the WIFI repeater, and this was an IP conflict so scp couldn't find the right location. Which on it's turn resulted in a access denied on scp. Weird was that everything did work out fine, i could get on the internet, surf, mail, but with scp it gave an conflict.

Changed it in the Gateway (removed the DHCP table), and assigned another ip to the terminal...

Now scp command worked as before!

It took me 8 hours to figure it out so I thought to share this little hickup that can really frustrate you freaking butt off...

Greets Pi @ir