1. Access Amazon EC2 – Linux Instance
i | P a g e
Table of Contents
Overview.......................................................................................................................................................1
Applies To......................................................................................................................................................1
Pre-requisites................................................................................................................................................1
Download Tools ........................................................................................................................................1
Generate Key – PuTTYkeygen .......................................................................................................................2
Type of Key................................................................................................................................................2
Key Bits......................................................................................................................................................2
Generate Key – Move Mouse ...................................................................................................................2
Set Passphrase ..........................................................................................................................................3
Save Public Key .........................................................................................................................................3
Saving Public Key .pub file.....................................................................................................................4
Save Private Key........................................................................................................................................4
Saving Private Key .ppk file ...................................................................................................................5
Amazon Console – Instance Public DNS........................................................................................................5
Create User – New........................................................................................................................................5
Create User – Switch User ........................................................................................................................6
Create User – Add User.............................................................................................................................6
Create User – Set Password......................................................................................................................6
Configure User – SwitchTo New User...........................................................................................................7
Configure User – Create Directory............................................................................................................7
Configure User – Authorized_Keys ...........................................................................................................8
Configure User – Copy Key........................................................................................................................8
Configure User – Add ssh key ...................................................................................................................9
Access Server - Host Name ...........................................................................................................................9
Access Server – SSH Auth............................................................................................................................10
Access Server – Login..................................................................................................................................10
2. Access Amazon EC2 – Linux Instance
1 | P a g e
Overview
After creating the first instance to connect to the amazon EC2 instance of Linux box; to login to the server
other than “ec2-user”. You need to create new user’s and import the ssh key into the users
authorized_keys file. This guide helps you to generate key, create user on the instance and login.
Applies To
Amazon AWS EC2 instance for Linux instance login only. In this guide we are generating “SSH2-DSA” with
2048 bits key. Though most of the Amazon guide suggests to generate “SSH2-RSA with 1024 bits” key.
Pre-requisites
First and foremost thing that needs to be done is generate ssh.
PuTTY
Login to the server’s
PuTTYgen
Public & Private Key Generator
Download Tools
From the below URL you can download puTTY and puTTYgen tools for connecting and generating keys.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
3. Access Amazon EC2 – Linux Instance
2 | P a g e
Generate Key – PuTTYkeygen
After downloading the keygen tool, launch the PuTTY Key Generator, click on “Generate” button once you
set the below options.
Type of Key
Choose the option “SSH2-DSA”
Key Bits
Set key bits “2048”
Generate Key – Move Mouse
Keep moving the mouse in the “blank area” highlighted in the 1st
screenshot, to generate the key; after
few mouse moves they will be generated (2nd
screenshot).
4. Access Amazon EC2 – Linux Instance
3 | P a g e
Set Passphrase
Upon generating the key, you need to set the key Passphrase and confirm passphrase. For the generated
ssh key.
Save Public Key
Click on the “Save public Key” button to save the generated public key to a file.
5. Access Amazon EC2 – Linux Instance
4 | P a g e
Saving Public Key .pub file
Assign a file name for the public key and click on “Save” button.
Save Private Key
Click on the “Save private Key” button to save the generated private key to a file.
6. Access Amazon EC2 – Linux Instance
5 | P a g e
Saving Private Key .ppk file
Assign a file name for the public key and click on “Save” button.
Amazon Console – Instance Public DNS
After launching the instance, public DNS and public IP is assigned to an instance. To identify the instance’s
public DNS / IP, Click Instances Click the Name Navigate to “Description” tab. In the Description
tab public IP and DNS information will be displayed.
Create User – New
Login into the Linux instance with “ec2-user”, search for the user what you are about to create.
To know if the user already exists, run the below command
cat /etc/passwd | grep vcp.muthukrishna
7. Access Amazon EC2 – Linux Instance
6 | P a g e
Create User – Switch User
To create a new user switch to the root user, to switch user run the below command
sudo su -
Create User – Add User
To create a new user switch to the root user, to switch user run the below command
useradd vcp.muthukrishna
Create User – Set Password
After creating the user set the password for the user to set password you need to enter the password two
times, run the below command
passwd vcp.muthukrishna
8. Access Amazon EC2 – Linux Instance
7 | P a g e
Configure User – SwitchTo New User
Next step is to add the ssh key, after creating the user switch to the new user, run the below command
sudo su - vcp.muthukrsihna
Configure User – Create Directory
Next step is to create new directory “.ssh” in the user’s home directory and modify permission of the
directory such that only the user can read, write or execute; run the below command
cd ~/
mkdir .ssh
chmod 700 .ssh
cd .ssh/
9. Access Amazon EC2 – Linux Instance
8 | P a g e
Configure User – Authorized_Keys
Next step is to create authorized_keys file in “.ssh” directory and modify permission of the file such that
only the user can read, write; run the below command
cd ~/.ssh/
touch authorized_keys
chmod 600 authorized_keys
Configure User – Copy Key
From the puTTY Key Generator, select the content in the highlighted area and copy the entire public key.
10. Access Amazon EC2 – Linux Instance
9 | P a g e
Configure User – Add ssh key
Insert the copied content from the puTTY key generator; and paste into the “authorized_keys” file and
subsequently save and exit the editor; see the screenshot below. The new user can login now.
Access Server - Host Name
In order to access the server, launch the puTTY tool. In the hostname / IP address post the “Public DNS”.
11. Access Amazon EC2 – Linux Instance
10 | P a g e
Access Server – SSH Auth
Click on SSH Auth option; browse for the Private key file that we generated earlier and click on “Open”
button to launch the ssh session of the server.
Access Server – Login
Upon clicking the “Open” button, you will be prompted for login credentials. Login with your respective
user ID and for the password, enter passphrase set during the key generator process.