Multiple user access on a running Amazon EC2 instance

share access amazon ec2

How to provide multiple user access to a running Amazon EC2 instance?

I was required to provide quick access to a running production Amazon EC2 instance. Now you could always share your passwords / keys around, but I couldn’t do that as they were used in multiple places for various reasons. On top of that this was just temporary access for about 15 minutes. For all of you who use Amazon EC2 regularly, would know that there is no way to create a new key pair in the console and just add it to the instance and reboot (if anyone knows of any way, please do let me know). But sometimes you are required to share or provide access to other people on a temporary basis (as in my case).

There are couple of ways to do this depending on your comfort level. First one is to modify the .ssh/authorized_keys file and add another public key in there and the follow on steps. I am not going to go in that one. I am documenting the one that I tried, which I found a little cumbersome but more manageable to my liking.

Depending on which kind of Amazon EC2 instance you are using first couple of steps might vary slightly. First you will login as your default user ubuntu for a Ubuntu instance or ec2-user. Hopefully you already have that configured over ssh or putty etc.
Then we create our superhero fictional user/s to whom we want to give access to.

Add hulk to sudoers by adding the following line to the file and saving it

Switch to default user again ubuntu or ec2-user and generate keys for our user hulk

In the last two steps hulk is the owner for .ssh and .ssh/authorized_keys

If the directory doesn’t exist

Now since we can’t use the hulk user just yet, we need to download the keys using our ubuntu default user or ec2-user using SCP or something to that effect. We now already have the files create in the home directory for our default user. Just connect and pass it on the Mr. Hulk.

Once the temporary access is not needed you can delete the user and the files by using the following

And there you go. Temporary (or long-term) access for multiple users on an Amazon EC2 instance.