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 ec2-user@xxx.amazonaws.com:/tmp
Permission denied (publickey).
lost connection
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 ec2-user@xxx.amazonaws.com:/tmp