Can't scp file from local to remote host - Permission denied
Solution 1
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.
Solution 2
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.
Related videos on Youtube
Jason Paddle
Updated on September 18, 2022Comments
-
Jason Paddle almost 2 years
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
drwxrwxr-x
Any ideas what can be the problem?
-
Jason Paddle almost 9 yearsThank'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. -
Jason Paddle almost 9 yearsAlso password is not wrong on 100%.
-
Jason Paddle almost 9 yearsThank'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 changeuser@myip
with real one nothing happen. Just hanging there and white dot blinking in console.. -
Jason Paddle almost 9 years
[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 -
Alex almost 9 yearsOk, try
rsync -v -e ssh SomeLocalFile root@remoteHost:~
. DoesSomeLocalFile
copied to the root's home ? Try alsowhich scp
and check permissions on founded path forscp
on remote server -
daid almost 9 yearsConfirm port 22 is used?
nmap -PN localhost
where localhost is verbatim. Keep in mind it works like this:ssh -p 22
andscp -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'"