Why does Amazon release private keys instead of public keys?

Solution 1:

Thinking more deeply about the authentication process, what needs to be kept secret? Amazon knows the public half of the key, and anybody can know the public half. The public half of the keypair, when matched with the private half, denotes that the private half was used to authenticate.

You private key that is provided to you when Amazon generates a keypair for you is only useful if you're the only one that has it. If it's not a secret, then anybody else who knows it can also authenticate to anybody who holds the public half of the keypair.

Whoever is being authenticated must hold the private half. It's ok if everybody in the world can authenticate you by holding the public half of the key, but only you should be in control of the private half.

Solution 2:

Amazon provides key generation services because some operating systems (cough, Windows, cough) may not make it easy to generate the SSH keypairs.

With SSH (and SFTP), the public key is installed in the user's authorized_keys file as the EC2 instance starts up. The private key is held only by the user and is presented to authenticate against the server.

From the documentation at:

http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateKeyPair.html

it appears that Amazon generates the keypair on their servers and sends you the private key via HTTPS. This is perhaps less than perfect (ideally, you and no one else will have possession of the private key), but probably not terribly so, given that this all occurs in the context of your authenticated session and only you (and Amazon temporarily) see the private key. You can also always generate and upload your own public key for EC2 use, while keeping the private key strictly private.

For setting up SFTP users for key authentication, they should be generating SSH keys on their machines. Once they generate a key pair, they should only be sending you the public key to install in the relevant authorized_keys file. The private key, as the name implies, is private.

Solution 3:

Public key authentication works in the reverse direction to the way you're probably thinking. The public key encrypts messages and the private key decrypts them. The server stores the account holder's public key and uses it to encrypt a message. Only the holder of the private key can decrypt that message.

If you send someone a secret encrypted with their public key, if they can tell you what that secret is, then you know they hold the matching private key. The user is then authenticated.

AWS requires you to download and save your private key because they wont store it, for security reasons. Because the private key is not stored anywhere on AWS, you can be confident that your EC2 instance is secure.

Solution 4:

In one sense, it doesn't matter. A private/public key pair consists of two parts, and which of them is the public one is up to you. If something is encrypted with one key, you need the other one to decrypt it. If you have published one key publicly and not the other, the private key is the one you didn't publish.

Getting to your actual question: presumably the key Amazon gives you is to allow you to control your own resources, so it should not be given to other people. In this context, you have to trust Amazon to have your private key, at least for long enough to get set up.

If you want your customer to log in this way, you need them to give you a key they are prepared to share with you, so therefore their public key. You install this on the server in authorized_keys, which is effectively saying "anyone who posesses the private key matching this public one may access this resource".