Scp – Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

scp

Trying to copy files over from serverB to serverA and get the following error:

root@server:~# scp /root/test.txt root@111.111.111.111:/home/somefolder/
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
lost connection

On serverA I created a public/private key pair with no passphrase.
On serverB I added the public key to the .ssh/authorized_keys file. Both the folder and file is owned by root.

I originally tried this with a passphrase… since it was not working I created another key without a passphrase. Both are giving the same results.

This is not a firewall issue.
serverA is centos.
serverB is ubuntu.

Best Answer

I was facing the same problem. Hope this will work for you.

scp -rp -i yourfile.pem ~/local_directory username@instance_url:directory

Permission should also be correct to make this work.