SCP Permission denied (publickey). on EC2 only when using -r flag on directories

user3015797 picture user3015797 · Jan 5, 2014 · Viewed 122.5k times · Source

scp -r /Applications/XAMPP/htdocs/keypairfile.pem uploads ec2-user@publicdns:/var/www/html

where uploads is a directory returns Permission denied (publickey).

However

scp -i /Applications/XAMPP/htdocs/keypairfile.pem footer.php ec2-user@publicdns:/var/www/html

works (notice the flag change).

uploads is an empty folder

These are the file permissions for the uploads directory

drwxrwxrwx 3 geoffreysangston admin 102 Nov 15 01:40 uploads

These are the file permissions for /var/www/html

drwxr-x--- 2 ec2-user ec2-user 4096 Jan 5 20:45 html

I've tried changing html to 777 and that doesn't work either.

Answer

David Levesque picture David Levesque · Jan 6, 2014

The -i flag specifies the private key (.pem file) to use. If you don't specify that flag (as in your first command) it will use your default ssh key (usually under ~/.ssh/).

So in your first command, you are actually asking scp to upload the .pem file itself using your default ssh key. I don't think that is what you want.

Try instead with:

scp -r -i /Applications/XAMPP/htdocs/keypairfile.pem uploads/* ec2-user@publicdns:/var/www/html/uploads