Security – How to securely manage private keys for EC2-managed key pairs

amazon ec2Security

In order to launch an EC2 instance you need a key pair. How do you handle the situation where an engineer with acccess to the private key for that key pair leaves the company? Would it work to add individual ssh access, and deauthorize the initial key pair, immediately after instance launch?

Best Answer

When an employee or contractor leaves the company, you need to disable any privileged access they had to company resources. This includes (but is not limited to) your ssh key concerns:

  1. Remove the public ssh key from all authorized_keys files on all running instances. Replace them with a newly generated public ssh key which is known only to the people who should have access.

  2. Remove all keypair entries in EC2 that were known by the departed so that new instances cannot be started with those keypairs. Replace them with new keypair entries, perhaps with the same names if your

The alternative method you propose is also good and is one that I use: Disable the initial ssh key and add individual public ssh keys for each developer so they can log in with their normal private ssh key. This can be done for login to a shared account or with each developer getting their own individual user account (my preferred).

After an employee leaves, you'll not only have to clean up running servers, but also the process that adds the ssh keys to new servers. And, when an employee joins, you'll need to do the reverse: Add ssh keys to running servers and update the new server process.

This can be a bit more work to maintain lots of ssh keys across lots of servers, but that's where automation comes in.