While copying files (scp) to Amazon EC2 instance, got the following error:
$ scp ~/Downloads/pcre-8.31.tar.gz -i /Users/khanna/Downloads/k2.pem email@example.com:/tmp
Permission denied (publickey).
The error message is not that intuitive to debug but after some researching it turned out that the order of arguments was incorrect. This fixes that:
$ scp -i /Users/khanna/Downloads/k2.pem ~/Downloads/pcre-8.31.tar.gz firstname.lastname@example.org:/tmp