Ssh – How to scp from remote host to remote host with pem files and turning off strict host checking

scpssh

From my DEV server I'd like to copy files from my stage server to my prod server. I already have SSH keys setup between my DEV server and my stage server. But I haven't had any success trying to copy from STAGE to PROD when I'm on my DEV server.

For example, it works right now to tail a log file on my prod server if I run these commands from DEV:

ssh -T my-user@my-stage-ip << TAIL_SCRIPT
ssh -i my-key.pem -o 'StrictHostKeyChecking=no' my-user@my-prod-ip tail -f /var/www/mysite.com/logs/access.log
TAIL_SCRIPT

These are some of the commands I've tried to do without any success.

ssh -T my-user@my-stage-ip << COPY_SCRIPT
scp -i my-key.pem -o 'StrictHostKeyChecking=no' my-user@my-stage-ip:/my/file/path.txt my-user@my-prod-ip:/my/file/path.txt
COPY_SCRIPT

The error is:

scp: /my/file/path.txt: Permission denied

I also tried:

scp -i my-key.pem -o 'StrictHostKeyChecking=no' my-user@my-stage-ip:/my/file/path.txt my-user@my-prod-ip:/my/file/path.txt

This one also has an error:

Permission denied (publickey).
lost connection
Connection to my-stage-ip closed.

Can someone help me out? This is really frustrating.

Best Answer

Check the folder permissions on both sides in regards to the user you are utilizing. It may be as simple as you not having Read permissions on the sending side, or not having write permissions on the receiving side.

Related Question