Search This Blog

Thursday, July 4, 2013

Manage multiple Linux Users on Amazon EC2 Instance

Step 0. Login by default user, “ubuntu”:

1
ssh -i my_key.pem ubuntu@111.111.11.111

Step 1. Create a new user, we will call our new user “john”:

1
[ubuntu@ip-11-111-111-111 ~]$ sudo adduser gmsundar
Set password for “gmsundar” by:
1
2
[ubuntu@ip-11-111-111-111 ~]$ sudo su
[root@ip-11-111-111-111 ec2-user]$ passwd gmsundar
Add “gmsundar” to sudoer’s list by:
1
[root@ip-11-111-111-111 ec2-user]$ visudo
and add this to the last line:
1
gmsundar   ALL = (ALL)    ALL
Alright! We have our new user created, now you need to generate the key file which will be needed to login, like we have my_key.pem in Step 0.
Now, exit and go back to ubuntu, out of root.

Step 2. Creating the public and private keys:

1
[ubuntu@ip-11-111-111-111 ~]$ su gmsundar
Enter the password you created for “gmsundar” in Step 1.
1
2
3
4
5
6
7
[gmsundar@ip-11-111-111-111 ec2-user]$ cd /home/gmsundar/
[gmsundar@ip-11-111-111-111 ~]$ ssh-keygen -b 1024 -f gmsundar -t dsa
[gmsundar@ip-11-111-111-111 ~]$ mkdir .ssh
[gmsundar@ip-11-111-111-111 ~]$ chmod 700 .ssh
[gmsundar@ip-11-111-111-111 ~]$ cat gmsundar.pub > .ssh/authorized_keys
[gmsundar@ip-11-111-111-111 ~]$ chmod 600 .ssh/authorized_keys
[gmsundar@ip-11-111-111-111 ~]$ sudo chown gmsundar:ubuntu .ssh
In the above step, gmsundar is the user we created and ubuntu is the default user group.
1
[gmsundar@ip-11-111-111-111 ~]$ sudo chown gmsundar:ec2-user .ssh/authorized_keys

Step 3. Now you just need to download the key called “gmsundar”

1
2
[gmsundar@ip-11-111-111-111 ~]$ sudo cp gmsundar /home/ubuntu/
[gmsundar@ip-11-111-111-111 ~]$ sudo chmod 777 /home/ubuntu/gmsundar
Now come to local machine’s terminal, where you have my_key.pem file and do this:
1
scp -i my_key.pem ubuntu@111.111.11.111:/home/ubuntu/gmsundar gmsundar
The above command will copy the key “gmsundar” to the present working directory on your local machine. Once you have copied the key to your local machine, you should delete “/home/ubuntu/gmsundar”, since it’s a private key.
Now, one your local machine chmod gmsundar to 600.
1
chmod 600 john

Step 4. Time to test your key:

1
ssh -i gmsundar gmsundar@111.111.11.111
So, in this manner, you can setup multiple users to use one EC2 instance!!

No comments:

Post a Comment