It's driving me nuts! I just want to transfer one simple file from laptop to server.

I'm using ubuntu on both machines.

So I have:

-rwxr-xr-x 1 sandro    414622 2011-10-14 23:42 sandrophoto-html.tar.gz

And I'm sending it using:

sudo scp -P XXXX sandrophoto-html.tar.gz [email protected]:/media/xx/xx/xx

And I get: scp: /media/xx/xx/xx/sandrophoto-html.tar.gz: Permission denied

p.s. I might be doing this other way around - I want to send file tar.gz that is located on my desktop, to remote server into the folder /media/yadayda

  • 7
    In my case, It was security reason on the receiving side, I had to chmod the directory to allow the remote user to write the file (i chmod 777 the directory - but it is internal lab)
    – ilansch
    Commented Aug 10, 2017 at 13:43
  • In my case, it was an ownership issue from the source side. Go to the source directory and change the ownership | sudo chown [username] [directoryname] |
    – ewalel
    Commented Jan 3, 2022 at 8:54
  • scp -i /Users/myusername/.ssh/sshuser ~/file.txt [email protected]:~/. In my case it was a lack of path to my private key.
    – neoswf
    Commented Oct 30, 2023 at 21:43

8 Answers 8


You have things in the right order from what I understand, the general way an scp is done is:

scp sourceuser@sourcehost:/path/to/source/file destinationuser@destinationhost:/path/to/destination/

Judging by your question, you have a local file you want to send to the destination server. So you have the right syntax which is good!

If you're getting permission denied, then you're not using the correct username or something's amiss with the authentication. Most likely, it's because the sudo command only works locally, for starters, so it won't give you root on the remote box, so that's probably the problem. Make sure that the user you are logging in as on the remote server has write permissions to the location you're trying to write to.

If the problem is the destinationuser doesn't have access to that location without sudo, move the file to the destinationuser's home folder then sudo mv the file from the shell on the other server to put it in the right location.

  • 14
    Thank you, I had to add write permission to destination directory
    – PiKey
    Commented Aug 26, 2015 at 18:50
  • @PiKey This should be an answer
    – Code-Guru
    Commented Aug 16, 2019 at 16:32
  • All of sudden I am facing that permission denied issue. I simply run this script and it started working.sudo chown -R ec2-user ~/my-path
    – Santosh
    Commented Jun 9, 2023 at 9:17

Hi had this same permission error problem solved it this way

Make sure the directory you are copying to on is owned by the user username

chown username downloads

On your local machine then do

sudo scp filename.zip [email protected]:/etc/Myfiles/downloads


  • thx, was permissions, specifically here I had to use chmod on the destination folder at remote server Commented Aug 14, 2017 at 23:21
  • 1
    Which chmod number? I had to use chmod -R 777 folder_path. Using 771 didn't work for me.
    – Juan Rojas
    Commented May 27, 2020 at 5:15

Permisssion Denied means you are not the root of the server. You just hold an account there. So in that case you need to do this:

sudo scp -r /path2yourFolder/ username@server_Ip:/home/username

This will copy to your home directory on server.

This will also work:

scp -r /path2yourFolder/ username@server_Ip:~/
  • 4
    lifesaver! :~/ did it for me.
    – trdavidson
    Commented Nov 22, 2016 at 10:14
  • 1
    ~/ is indeed the way, -r is for recursively copy entire directory.
    – Noam Manos
    Commented Apr 25, 2018 at 10:04
  • This command works for me and I understood the problem , "you are not the root of the server"
    – Kuhan
    Commented Jan 25, 2021 at 7:01

I had a similar problem, it happened because ssh takes -p xxxx for specifying the port while scp takes -P xxxx to specify the port. Minor inconsistency, so easy to miss :(

  • 1
    Praise you. Don't mind me if I add a couple of Google-able keywords to make this more visible: scp doesn't work Permission denied (publickey). lost connection for ec2 compute.amazonaws.com Commented Dec 15, 2017 at 20:02
  • Awesome, I already tried --port to prevent that error, but that was not successful for me. Your answer solved it.
    – a.t.
    Commented Dec 2, 2023 at 16:04

This error occurred for me when the file already existed in the target location and the existing file had read-only permissions (preventing the file from being overwritten). In my case, I just logged in and deleted the existing file and that corrected the problem.

  • 1
    I'll upvote this because as a short-term solution, I was able to rename the destination file (which felt safer than deleting) and then upload from my local computer to the remote destination, and it worked. But what I want to learn is why using scp to upload as a user who is a member of a group who had "w" permissions why I couldn't overwrite the file.
    – Ryan
    Commented Dec 19, 2019 at 16:14

I was trying to copy from my local machine as username@localhost; the SSH key I was using wasn't registered to access my localhost, so I was getting permission denied. When I removed that from the source portion, it worked.


Had the same problem. I found out that the directory containing my source file did not have enough permission. So I just changed the mode recursively using:chmod -R 771 directory_path on the source machine.


If there is an identically named file owned by root on the remote host (target) the transfer will fail. This assumes you are running scp as an ordinary user on both hosts, i.e. your remote host user is not root.

You must log in to answer this question.