Connecting to Linux/UNIX AWS Instances from Windows Using PuTTY

时间:2022-01-13 01:51:01
Topics

Prerequisites

  • Install PuTTY

Download and install PuTTY from the PuTTY download page. Be sure to install the entire suite.

  • Get the ID of the instance

You can get the ID of your instance using the Amazon EC2 console (from the Instance ID column).

  • Get the public DNS name of the instance

You can get the public DNS for your instance using the Amazon EC2 console (check the Public DNS column; if this column is hidden, click the Show/Hide icon and select Public DNS)..

  • Locate the private key

You'll need the fully-qualified path of the .pem file for the key pair that you specified when you launched the instance.

  • Enable inbound SSH traffic from your IP address to your instance

Ensure that the security group associated with your instance allows incoming SSH traffic from your IP address. For more information, see Authorizing Network Access to Your Instances.

Converting Your Private Key Using PuTTYgen

PuTTY does not natively support the private key format (.pem) generated by Amazon EC2. PuTTY has a tool named PuTTYgen, which can convert keys to the required PuTTY format (.ppk). You must convert your private key into this format (.ppk) before attempting to connect to your instance using PuTTY.

To convert your private key

  1. Start PuTTYgen (for example, from the Start menu,      click All Programs > PuTTY > PuTTYgen).
  2. Under Type of key to generate, select SSH-2 RSA.

        Connecting to Linux/UNIX AWS Instances from Windows Using PuTTY               

  1. Click Load. By default, PuTTYgen displays only files with      the extension .ppk. To locate your .pem file, select the      option to display files of all types.

       Connecting to Linux/UNIX AWS Instances from Windows Using PuTTY

  1. Select your .pem file and click Open.      Click OK to dismiss the confirmation dialog box.
  2. Click Save private key to save the key in the format      that PuTTY can use. PuTTYgen displays a warning about saving the key      without a passphrase. Click Yes.

Note

A passphrase on a private key is an extra layer of protection, so even if your private key is discovered, it can't be used without the passphrase. The downside to using a passphrase is that it makes automation harder because human intervention is needed to log on to an instance, or copy files to an instance.

  1. Specify the same name for the key that you used for the key pair (for      example, my-key-pair). PuTTY automatically adds      the .ppk file extension.

Your private key is now in the correct format for use with PuTTY. You can now connect to your instance using PuTTY's SSH client.

 

Starting a PuTTY Session

To start a PuTTY session

  1. In the Category pane, select Session and complete      the following fields:
    1. In the Host Name box, enter user_name@public_dns_name. Be sure to specify the       appropriate user name for your AMI. For example:
      
  • For an Amazon Linux        AMI, the user name is ec2-user.
  •   
  • For a RHEL5 AMI, the        user name is often root but might be ec2-user.
  •   
  • For an Ubuntu AMI, the        user name is ubuntu.
  •   
  • Otherwise, check with        your AMI provider.
  • Under Connection type, select SSH.
  • Ensure that Port is 22.
  •  Connecting to Linux/UNIX AWS Instances from Windows Using PuTTY

    1. In the Category pane, expand Connection,      expand SSH, and then select Auth. Complete the      following:
      1. Click Browse.
      2. Select the .ppk file that you generated for your key pair,       and then click Open.
      3. (Optional) If you plan to start this session again later, you can       save the session information for future use. Select Session in       the Category tree, enter a name for the session in Saved       Sessions, and then click Save.
      4. Click Open to start the PuTTY session.

       Connecting to Linux/UNIX AWS Instances from Windows Using PuTTY

    1. If this is the first time you have connected to this instance, PuTTY      displays a security alert dialog box that asks whether you trust the host      you are connecting to.
    2. (Optional) If you've launched a public AMI, verify that the fingerprint      in the security alert matches the fingerprint that you obtained in step 1.      If these fingerprints don't match, someone might be attempting a      "man-in-the-middle" attack. If they match, continue to the next      step.
    3. Click Yes. A window opens and you are connected to your      instance.

    Note

    If you specified a passphrase when you converted your private key to PuTTY's format, you must provide that passphrase when you log in to the instance.

     

     

    Transferring Files to Your Instance with the PuTTY Secure Copy Client

    The PuTTY Secure Copy client (PSCP) is a command-line tool that you can use to transfer files between your Windows computer and your Linux/UNIX instance. If you prefer a graphical user interface (GUI), you can use an open source GUI tool named WinSCP. For more information, see Transferring Files to Your Instance with WinSCP.

    To use PSCP, you'll need the private key you generated in Converting Your Private Key Using PuTTYgen. You'll also need the public DNS address of your Linux/UNIX instance.

    The following example transfers the file Sample_file.txt from a Windows computer to the /usr/local directory on a Linux/UNIX instance:

    C:\> pscp -i C:\Keys\my-key-pair.ppk C:\Sample_file.txt user_name@public_dns:/usr/local/Sample_file.txt