04 Connect To An AWS EC2 Instance - Windows and PuTTY
04 Connect To An AWS EC2 Instance - Windows and PuTTY
When you have created and launched an AWS Linux EC2 instance, you can connect to it from your computer
using the Secure Shell (SSH) protocol. PuTTY is a free SSH client that allows you to do this from a local computer
running Windows. Once the connection has been established, you work within the EC2 instance just like you
would on a local computer running Linux.
To follow this tutorial, you will first need to create and launch a Linux EC2 instance to which you will connect.
Instructions for this are found in the tutorial titled, Create a Basic Elastic Cloud Compute (EC2) Instance.
You must have an AWS account. If you have one, click HERE to sign into it.
Figure 4.1.
Cloud technology is evolving so fast that it is likely that some details in the primer may no longer match reality when you are trying to use it. If you find
mismatches (e.g. broken third-party links), please send them to [email protected] so that we can feed them into the next release of the primer.Cab
ipsum, quia consed unda am, sam doluptas nem vid maionsed ut aliquia ssinctotae pra es maiorro ribus.
6. Click the box next to your private key file (.pem) to select it (Figure 4.3).
Figure 4.3.
7. Click on Open.
8. Click OK to close the PuTTYgen Notice pop-up window
2
9. In PuTTY Key Generator, make sure Type of key to generate value is set to RSA (Figure 4.4).
Figure 4.4.
Figure 4.5.
Figure 4.6.
The Public DNS for your instance is displayed in AWS in the EC2 Management Console Instance Description in the
middle of the screen.
3. Set the Port to 22.
4. Set the Connection Type to SSH.
4
5. C
lick on the + next to SSH to expand the choices in the Category pane on the left of the PuTTY Configuration
window under Connection (Figure 4.7).
Figure 4.7.
6. C
lick Browse under Authentication parameters and navigate to the directory where your PuTTY Private Key (.ppk) file
is located and select it.
7. Click Open.
If you want to save these settings to use later, navigate to Sessions in the PuTTY Category tree. Enter a name in the
Saved Sessions box and click Save on the right.
8. Click Open in PuTTY Configuration to connect to your Instance.
If this is the first time you have connected to your Instance, a PuTTY Security Alert will ask you whether to proceed with
the connection (Figure 4.8).
9. Click Yes to complete the connection.
Figure 4.8
5
The EC2 instance window will appear (Figure 4.9).
To view files and directories in a Linux (Ubuntu) instance, use the ls (list) and cd (change directory) commands.
Figure 3.11
Figure 4.10
6
Transferring Files Using WinSCP
1. Download WinSCP. https://winscp.net/eng/download.php
2. Click on Installation package (Figure 4.11) and then use the default installation options.
Figure 4.11
3. Click on the Desktop icon to start WinSCP.
4. Click on New Site (Figure 4.12).
Figure 3.13
Figure 4.12
7
5. Enter the Public DNS displayed in your EC2 Management Console Instances window into the Host Name box.
6. Type ubuntu in the User name boxs.
7. Select the Advanced dropdown menu and, under Sessions, select Advanced.
8. Click on Authentication under SSH (Figure 4.13).
Figure 4.13
Figure 4.13
Figure 4.13
9. C
lick on the button under Private key file and navigate to the folder where your PuTTY Private Key (.ppk) file
is located and select it.
Instructions for creating a PuTTY Private Key (.ppk) file can be found in the tutorial titled Connect to an AWS EC2
Instance – Windows & PuTTY.
10. Click on the OK button to close the Advanced Site Settings window.
If you want to save your settings to use again later, click on the Save button in the WinSCP Login window (Figure 4.14).
A pop-up window will appear where you can name the settings.
11. Click the Login button.
8
Figure 3.17
Figure 4.14
12. Th
e first time you connect to your instance, you will be asked about connecting to an unknown server. Click the Yes
button to continue (Figure 4.15).
Figure 4.15
NOTE: If you stop your EC2 instance and restart it, a new Public DNS will be assigned. You will need to
copy and paste this into the WinSCP Host name box before you can connect.
9
After you have connected, the left pane of the window will display the file contents of your computer and the right pane
displays the contents of your EC2 instance (Figure 4.16).
Figure 4.16
13. D
rag and drop files from your computer into your EC2 instance to process. When processing is complete, drag and
drop the products from EC2 to your computer.
Important: Files must be transferred from your EC2 instance to your computer before you terminate the instance!
When you transfer files, a copy of the files will be left on the instance. These will be deleted when the
instance is terminated.
10
Transferring Files Using PuTTY Secure Copy (SCP)
Windows 10 Users
1.Click on the Start button at the extreme left of the Taskbar (Figure 4.17).
Figure 4.17
Figure 4.18
11
Windows 7 users
1. Click on the Start button at the left of the Taskbar.
2. Type cmd in the Search programs and files box (Figure 4.19).
Figure 4.19
2. M
ove your awskey.ppk file to your Downloads folder using Windows File Explorer or provide a path to the folder in
which your .ppk file is located.
3. Navigate to your Downloads folder using the change directory (cd) command at the Windows command prompt.
C:\Users\username>cd Downloads
12
4. T
ype the PSCP command, which includes your .ppk filename (and path if necessary), the name of the file you want
to transfer, the Public DNS of your EC2 instance, and the path to a folder in your instance: (Figure 4.20).
Figure 4.20
Command syntax: brackets <> indicate optional paths to your .ppk file and the file you want to move if they are not in
the folder you are in
Move a file out of your EC2 instance
1. At the Windows command prompt, type:
Example: Move a product generated from an application out of your EC2 instance PRODUCT directory to the Data
folder on your Windows computer.
2. U
se Windows File Explorer to move a copy of my awskey.ppk file to your Data folder or provide a path to the folder
in which your .ppk file is located.
NOTE: If you don’t include a local destination path and folder in the command, the file will download into the
folder the command is run from. In this case, the command syntax would be:
C:\> pscp -i C:\[path]\yourkey.ppk ubuntu@publicDNS:/home/ubuntu/[folder]/filename
3. At the Windows command prompt, navigate to your Data folder using the change directory (cd) command:
C:\> cd Data
And press Enter.
4. A
t the command prompt, type the PSCP command, which includes your .ppk filename, the Public DNS of your
EC2 instance, and the name of the file you want to transfer.
C:\> pscp -i C:\[path]\yourkey.ppk ubuntu@public_DNS:/home/ubuntu/[path]/yourfilename C:\[local_destination_path]
Important: Files must be transferred from your EC2 instance to your computer before you terminate the instance
or they will be deleted!
13