Connecting Securely to Amazon EC2 Server with SFTP
With WinSCP you can easily upload and manage files on your Amazon EC2 (Elastic Compute Cloud) instance/server over SFTP protocol.
Before starting you should:
Collect information about your EC2 instance:
- Host name: Check Public DNS column on Instances page of Amazon EC2 console. Note that the public DNS may change when instance is restarted.
- Host key fingerprint: On the first connect you will be prompted to verify server host key.
- You can locate key fingerprint in server’s initial start log, when host keys are generated.1) Use Actions > Get System Log command on Instances page of Amazon EC2 console:
aws ec2 get-console-output command.
Look for RSA (or DSA) key fingerprint. WinSCP does not support ECDSA keys.
- If you did not save the fingerprint on the first instance run, but you have another EC2 instance that you can connect to safely (you know its fingerprints), you can connect to the target instance using private IP from the trusted instance. Staying within private Amazon network keeps you safe from man-in-the-middle attacks. When on the trusted instance terminal, you can use following commands to collect fingerprints:
$ ssh-keyscan <target_instance_private_ip> > ec2key
$ ssh-keygen -l -f ec2key
2048 cc:3d:ac:a7:13:61:4c:14:25:47:80:ae:f1:f3:aa:10 172.31.30.101 (RSA)
256 ea:bc:4d:5f:ae:00:48:75:45:ba:97:43:fe:e1:a3:e9 172.31.30.101 (ECDSA)
With OpenSSH 6.8 and newer, you need to add
-E md5 to display MD5 fingerprint.
- If you do not have another trusted instance, you can create new temporary instance, just for the purpose of collecting the keys. First find keys for the new temporary instance, using it’s initial start log. Then collect keys of the target instance by connecting to it from the temporary instance. After that you can discard the temporary instance.
Start WinSCP. Login dialog will appear. On the dialog:
- Make sure New site node is selected.
- On New site node, make sure SFTP protocol is selected.
- Enter your EC2 instance public DSN name (see above) into Host name box.
- User name differs with instance type:
- For an Amazon Linux AMI, the user name is
- For a RHEL5 AMI, the user name is either root or
- For an Ubuntu AMI, the user name is
- For a Fedora AMI, the user name is either
- For SUSE Linux, the user name is
- Press Advanced button to open Advanced site settings dialog and go to SSH > Authentication page.
- In Private key file box select the
.pem private key file. WinSCP will need to convert the key to its
.ppk format (you can then use the converted
.ppk key for example with PuTTY SSH client).
- Submit Advanced site settings dialog with OK button.
- Save your site settings using Save button.
- Login using Login button.
- Verify the host key by comparing fingerprints with those collected before (see above).
If you are managing a large amount of servers, and it is not feasible for you to save a site for each of them in WinSCP, consider using an user script that injects "Open in WinSCP" link to an Amazon EC2 management portal.
Connecting to EC2 instance in VPC