Differences
This shows you the differences between the selected revisions of the page.
guide_amazon_ec2 2019-01-25 | guide_amazon_ec2 2024-08-19 (current) | ||
Line 1: | Line 1: | ||
- | ====== Connecting Securely to Amazon EC2 Server with SFTP ====== | + | ====== 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|SFTP protocol]]. | With WinSCP you can easily upload and manage files on your Amazon EC2 (Elastic Compute Cloud) instance/server over [[sftp|SFTP protocol]]. | ||
+ | |||
+ | ===== Direct Connection ===== | ||
Before starting you should: | Before starting you should: | ||
* [[guide_install|Have WinSCP installed]]; | * [[guide_install|Have WinSCP installed]]; | ||
- | * [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/launching-instance.html|Have Amazon EC2 instance running]]; | + | * [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-instance-wizard.html|Have Amazon EC2 instance running]]; |
- | * [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/authorizing-access-to-an-instance.html|Have enabled inbound SSH traffic from your IP address to your instance]]; | + | * [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/creating-security-group.html|Have enabled inbound SSH traffic from your IP address to your instance]]; |
* Have your [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html|key pair]] ready; | * Have your [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-key-pairs.html|key pair]] ready; | ||
Line 14: | Line 16: | ||
* 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 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 [[ssh_verifying_the_host_key|verify server host key]]. | * Host key fingerprint: On the first connect you will be prompted to [[ssh_verifying_the_host_key|verify server host key]]. | ||
- | * You can locate key fingerprint in server's initial start log, when host keys are generated.((Using ''cloud-init'' script.)) Use //Actions > Get System Log// command on //Instances// page of Amazon EC2 console: \\ \\ &screenshotpict(ec2_hostkey) \\ \\ Alternatively use ''[[https://docs.aws.amazon.com/cli/latest/reference/ec2/get-console-output.html|aws ec2 get-console-output]]'' command. \\ Look for RSA (or DSA) key fingerprint. WinSCP does not support ECDSA keys. | + | * To securely acquire a fingerprint of the host key, use EC2 web-based terminal. Go to //Actions > Connect > EC2 Instance Connect > Connect// on //Instances// page of Amazon EC2 console. In the terminal, use ''[[https://man.openbsd.org/ssh-keygen|ssh-keygen]]'' command to display a fingerprint of any number of host keys algorithms. The following example shows SHA-256 and MD5 fingerprints of Ed25519 hostkey: \\ <code bash>sudo ssh-keygen -l -f /etc/<nohilite>ssh</nohilite>/ssh_host_ed25519_key |
- | * 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 [[wp>Man-in-the-middle_attack|man-in-the-middle attacks]]. When on the trusted instance terminal, you can use following commands to collect fingerprints: \\ <code> | + | sudo ssh-keygen -l -f /etc/<nohilite>ssh</nohilite>/ssh_host_ed25519_key -E md5 |
- | $ ssh-keyscan <target_instance_private_ip> > ec2key | + | </code> |
- | $ 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) | + | |
- | </code> 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. | + | |
~~AD~~ | ~~AD~~ | ||
Line 35: | Line 32: | ||
* For an Centos AMI, the user name is ''centos''. | * For an Centos AMI, the user name is ''centos''. | ||
* For a Fedora AMI, the user name is either ''fedora'' or ''ec2-user''. | * For a Fedora AMI, the user name is either ''fedora'' or ''ec2-user''. | ||
- | * For SUSE Linux, the user name is ''root''or ''ec2-user''. | + | * For SUSE Linux, the user name is ''root''·or ''ec2-user''. |
* Press //Advanced// button to open [[ui_login_advanced|Advanced site settings dialog]] and go to //[[ui_login_authentication|SSH > Authentication page]]//. | * Press //Advanced// button to open [[ui_login_advanced|Advanced site settings dialog]] and go to //[[ui_login_authentication|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 [[integration_putty|PuTTY]] SSH client). | * 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 [[integration_putty|PuTTY]] SSH client). | ||
Line 43: | Line 40: | ||
* [[ssh_verifying_the_host_key|Verify the host key]] by comparing fingerprints with those collected before (see above). | * [[ssh_verifying_the_host_key|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 [[guide_injecting_sftp_ftp_url_to_page|injects "Open in WinSCP" link to an Amazon EC2 management portal]].// | + | //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 the user script [[guide_injecting_sftp_ftp_url_to_page|*]].// |
===== [[vpc]] Connecting to EC2 instance in VPC ===== | ===== [[vpc]] Connecting to EC2 instance in VPC ===== | ||
Line 49: | Line 46: | ||
To connect to an EC2 instance in an Amazon VPC, you can tunnel through a [[https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html|NAT instance]]. | To connect to an EC2 instance in an Amazon VPC, you can tunnel through a [[https://docs.aws.amazon.com/vpc/latest/userguide/VPC_NAT_Instance.html|NAT instance]]. | ||
- | For details, see a guide to [[guide_tunnel|connecting to an SFTP server which can be accessed via another server only]]. | + | For details, see [[guide_tunnel|*]]. |
+ | |||
+ | ===== [[ssm]] Connecting using AWS SSM (Session Manager) ===== | ||
+ | |||
+ | In //Host name//, specify your //Instance ID//. | ||
+ | |||
+ | Press //Advanced// button to open [[ui_login_advanced|Advanced site settings dialog]] and go to //[[ui_login_proxy|Connection > Proxy page]]//. There: | ||
+ | |||
+ | * For //Proxy type//, select //Local//. | ||
+ | * In //Local proxy command//, specify: \\ <code>aws ssm start-session --target %host --document-name AWS-StartSSHSession --parameters "portNumber=%port" --profile <aws profile> --region <region></code> | ||
+ | * You may need to set //Do DNS name lookup at proxy end// to //Yes//. | ||
===== Further reading ===== | ===== Further reading ===== | ||
- | * Guide to [[guide_upload|uploading files to SFTP server]]; | + | * [[guide_upload|*]]; |
- | * Guide to [[guide_automation|automating operations]] (including upload); | + | * [[guide_automation|*]]; |
- | * [[faq_su|How do I change user after login (e.g. su root)?]] | + | * [[faq_su|*]] |
- | * [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/putty.html|Official guide for connecting using PuTTY/WinSCP]]; | + | * [[https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-linux-inst-from-windows.html|Official AWS guide for connecting using PuTTY/WinSCP]]; |
- | * Guide to [[guide_google_compute_engine|connecting to Google Compute Engine server with SFTP]]; | + | * [[https://docs.aws.amazon.com/transfer/latest/userguide/transfer-file.html#winscp|Official AWS guide for transfering files using a WinSCP]] |
- | * Guide to [[guide_microsoft_azure|connecting to Microsoft Azure Service with SFTP or FTPS]]. | + | * [[guide_google_compute_engine|*]]; |
+ | * [[guide_microsoft_azure|*]]. |