0% found this document useful (0 votes)
89 views13 pages

04 Connect To An AWS EC2 Instance - Windows and PuTTY

This document provides instructions for connecting to an AWS EC2 Linux instance from a local Windows computer using PuTTY and transferring files between the EC2 instance and the local computer. It explains how to generate a PuTTY private key, use PuTTY to connect to the EC2 instance over SSH, and use WinSCP or PuTTY SCP to transfer files both into and out of the instance. The goal is to allow users to process or analyze data on the EC2 instance by moving files in, and then retrieving result files before terminating the instance.

Uploaded by

Ariel MySQL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views13 pages

04 Connect To An AWS EC2 Instance - Windows and PuTTY

This document provides instructions for connecting to an AWS EC2 Linux instance from a local Windows computer using PuTTY and transferring files between the EC2 instance and the local computer. It explains how to generate a PuTTY private key, use PuTTY to connect to the EC2 instance over SSH, and use WinSCP or PuTTY SCP to transfer files both into and out of the instance. The goal is to allow users to process or analyze data on the EC2 instance by moving files in, and then retrieving result files before terminating the instance.

Uploaded by

Ariel MySQL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

CLOUD PRIMER

Connect to an AWS EC2 Instance –


Windows & PuTTY
Includes moving files into and out of an EC2 Instance

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.

Generate a PuTTY Private Key (.ppk) file


1. Download and install PuTTY.
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
2. Open the folder in which PuTTY was installed (default path is C: > Program Files > PuTTY).
3. Double click on the file puttygen.exe.
The first thing you will see is shown in Figure 4.1.

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.

National Aeronautics and


Space Administration

www.nasa.gov v1.0/August 2020


4. C
 lick on the Load button in PuTTY Key Generator (Figure 4.1) and navigate to the folder that contains the private
key file (.pem) created during the EC2 configuration process.
5. C
 lick on the PuTTY Private Key Files button in the lower right corner of the window (Figure 4.2) and select All Files
(*.*).

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.

10. Click Save private key.


11. Click Yes to close the PuTTYgen Warning pop-up window.
12. Navigate to the location you want to store your PuTTY Private Key file (.ppk) (Figure 4.5)

Figure 4.5.

13. Give the file a name.


14. Click Save.
15. Close the PuTTY Key Generator window.
3
Once you have generated a private key, you can use it whenever you need to connect to a new EC2 instance.

Connect to the EC2 instance


1. Click on the desktop icon or the putty.exe file in the PuTTY folder to open PuTTY.
2. Type ubuntu@your_public_DNS in the Host Name (or IP address) box (Figure 4.6).

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).

You are now connected to your EC2 instance!


Figure 4.9

To view files and directories in a Linux (Ubuntu) instance, use the ls (list) and cd (change directory) commands.

Move files into & out of an AWS EC2 Instance – Windows


You can transfer files into and out of a Linux EC2 instance from a local computer running Windows by either of these methods:
1. W
 indows Secure Copy (WinSCP): WinSCP provides a graphical interface (GUI) that allows you to drag and
drop files between your local computer and your AWS instance. This is similar to using Windows File Explorer.
 uTTY Secure Copy: PuTTY Secure Copy is run from the Windows Command Prompt.
2. P
Using an EC2 instance to process/analyze data requires that you move the files to be processed to the instance, and then
remove the resulting products before the instance is terminated.

Find Your EC2 Instance Public DNS


1. Open the AWS “Instances” window in the EC2 Management Console (Figure 4.10).
The Public DNS of your EC2 instance displayed in this window will be used in the next two sections.

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

2. Scroll down the list of Apps to the Windows System folder.


3. Select Command Prompt.
You can also click the Start button and type cmd; then select Command Prompt from the search results.
In either case, the Command Prompt window will open (Figure 4.18).

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

3. Select Command Prompt from the search results.


The Command Prompt window will open as in Figure 4.18 above.
When using PSCP to transfer files between your computer and your EC2 instance, your PuTTY Private Key (.ppk) file
must be in the folder you are working in, or you must provide a path in the PSCP command to the folder in which the
file is located.
For example, if AWSkey.ppk file is stored in a folder named keys, include the path C:\Users\username\keys\AWSkey.ppk in the
PSCP command.

Move a file into your EC2 instance


1. At the Windows command prompt, type (notice where spaces are placed):

C:\> pscp -i yourkey.ppk yourfilename ubuntu@public_DNS:/home/ubuntu/

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

and press Enter.

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).

C:\> pscp -i awskey.ppk S1A_EW_GRD.zip [email protected].


com:/home/ubuntu/

Figure 4.20

C:\> pscp -i C:\<path>\yourkey.ppk C:\<path>\yourfilename ubuntu@public_DNS:/home/ubuntu

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:

C:\> pscp -i yourkey.ppk ubuntu@publicDNS:/home/ubuntu/yourfilename C:\[local_destination_path]\[folder]

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]

C:\> pscp -i awskey.ppk [email protected]:/home/ubuntu/PRODUCT/F2_unw_


phase.tif C:\data_files

Important: Files must be transferred from your EC2 instance to your computer before you terminate the instance
or they will be deleted!
13

You might also like