I have checked many postings regarding 'Permission denied' error in using scp, but couldn't find the answer for my problem.
There are two ubuntu servers (let's say server 'A' and 'B') on the same network in AWS, and when I tried to copy one file to another server, A to B is not working, but from B to A works. (Please see below)
On Server 'A',
ubuntu@server-a ~ $ ls -alt server* -rwxr-xr-x 1 ubuntu ubuntu 8152 Aug 9 14:26 server.xml.bak ubuntu@server-a ~ $ scp -P 443 server.xml.bak [email protected]:/home/ubuntu/ Permission denied (publickey). lost connection ubuntu@server-a ~ $ scp -P 443 /home/ubuntu/server.xml.bak [email protected]:/home/ubuntu/ Permission denied (publickey). lost connection Also I tried to copy the remote file to here, and it failed as well.
ubuntu@server-a ~ $ scp -P 443 [email protected]:/home/ubuntu/sakila.sql . Permission denied (publickey). But from Server 'B', all worked.
ubuntu@server-b ~ $ scp -P 443 [email protected]:/home/ubuntu/server.xml.bak . server.xml.bak 100% 8152 8.0KB/s 00:00 ubuntu@server-b ~ $ scp -P 443 sakila.sql [email protected]:/home/ubuntu/ sakila.sql 100% 3153KB 3.1MB/s 00:00 As you see, it is not the permission issue - all operations were done by 'ubuntu' on 'ubuntu' home and files are also owned by 'ubuntu' with 755 mode.
So now I'm confused what is wrong.
scp -vand found it's due to missing priv key. For security reason I removed all priv keys on servers and use Pageant instead for priv key management. I've connected B (bastion server), and opened another PuTTY terminal, connected B there again, and then connect A via ssh. So B to A works (Pageant manages priv key for B) but A to B didn't work... I upload priv key to A for testing and then scp command from A also works. Since I can't keep priv key on servers, I think I should only use scp command on B.