I have trying to copy some files from local machine to remote host.

root@local:~$ scp /var/www/html/file.php root@remote_host:/var/www/html/test/

The result is

scp: /var/www/html/test: Permission denied

root@remote_host's password: Permission denied, please try again.

Those are the rights of the folder on the remote machine


Any ideas what can be the problem?

  • There are many possible reasons and basically you have not correctly set up the authorized_keys in remote_host:/.ssh/. You should take basic troubleshooting and report what you observe in order to let others help. Jul 23, 2015 at 11:39
  • But if they are not correctly defined I will not be able to connect and log in this server at all but I can.. Jul 23, 2015 at 11:43
  • e.g. if there's an entry of your local host's pub key in remote_host:/.ssh/authorized_keys, then you'd be authenticated with pki instead of inputting password. However, say if your local host's ip has recently changed, this would be failed. I'd suggest you to refer a ssh tutorial. Jul 23, 2015 at 11:59
  • if there's an entry of your local host's pub key in remote_host:/.ssh/authorized_keys, then you'd be authenticated with pki instead of inputting password. I understand now. I never before logged without password on that server. No, my IP is the same as always. Jul 23, 2015 at 12:02

2 Answers 2


If you login as The root then root has all permissions allowed, regardless permissions on any directory (exclusion can be only if directory has system immutable flag over chflags(1))

You either providing a wrong password or remote host used public key authentication only.

  • Thank's for the answer. or remote host used public key authentication only I'm not familiar whit this. I can login in as root without any problem but I can copy. Jul 23, 2015 at 11:35
  • Also password is not wrong on 100%. Jul 23, 2015 at 11:37
  • Ok, try rsync -v -e ssh SomeLocalFile root@remoteHost:~ . Does SomeLocalFile copied to the root's home ? Try also which scp and check permissions on founded path for scp on remote server
    – Alex
    Jul 23, 2015 at 15:05

The reasons could be various, of course.

The most obvious answer is that, for one reason or another, you cannot be authenticated by the remote system. However, since you are outputting the directory permissions on the remote system, I assume you have the rights and ability to access it by some means (but perhaps not by ssh).

So, the first thing to do is to ssh to the machine and make sure you can actually write to that location (which you may have already tried):

ssh root@remote_host
cd /var/www/html/test/
touch scratch

If you can see the empty file scratch, then you know you can write.

Supposing you can properly access the system but the above does not work, it is also possible there is not actually write permissions on the directory. One example would be if the directory on the remote machine is within a mounted filesystem of a certain type, for example NTFS (which won't give you reliable UNIX-type modes), and the kernel sets it to read-only because it wasn't mounted via fuse to give write permissions. You'd need to check more carefully on the local settings, but this would be a very unusual setup unless it is new (or designed that way).

Debugging the system from here would be hard for me, so I'll just give you an alternate method to try. If you can access the system via ssh and write files from within the system, then a way to do it is just to do the opposite way around, if your local computer is not behind a firewall, etc.

You can easily find the IP of the computer you ssh'd from without even moving to another terminal. Let's just make it an environment variable for simplicity:

export IP="`echo $SSH_CLIENT | awk '{print $1}'`"

I generally include this line in, for example, ~/.bashrc because I find it handy.

In any case, then

scp user@$IP:/var/www/html/file.php /var/www/html/test/

Of course, if you want to be running a program to do these updates automatically on the local machine, this will not resolve your problem just yet! There are ways to resolve that by calling commands via SSH (so you would be calling an scp via ssh, which seems counter-intuitive); however, for it to be fully automated you'd need to set up an ssh key, and make no password for the key. This is not the kind of thing I would recommend for root access to a machine, and some kind of debugging with the remote machine's ssh needs to be done that is blocking scp.

  • Thank's for this answer. So I've tried also back way while I'm logged into remote machine. When I write scp user@myip:/var/www/html/file.php /var/www/html/test/ of course i change user@myip with real one nothing happen. Just hanging there and white dot blinking in console.. Jul 23, 2015 at 11:56
  • [root@remote_host /var/www/html/test ]# touch test, [root@remote_host /var/www/html/test ]# ls -al, -rw-r--r-- 1 root root 0 Jul 23 14:55 test .. so I can create file in the folder Jul 23, 2015 at 11:56
  • Confirm port 22 is used? nmap -PN localhost where localhost is verbatim. Keep in mind it works like this: ssh -p 22 and scp -P 22 for port 22 (default). Case of p and P is not symmetric. I think no problem, but you might not mention details of your server. If port is 22, you can use the following with the target and location fields identical to scp, basically: alias scpresume="rsync --partial --progress --rsh=ssh -e 'ssh -p 22'"
    – daid
    Jul 23, 2015 at 16:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.