[AWS] How to use SSH to connect to the EC2 instance (virtual machine) on aws?

Table of contents

0. Environment

1. Example of connection result

2. SSH connection ideas

3. Specific steps

1) Install and run the ssh service

2) Start the ssh service

3) Find the running EC2 instance on AWS, and connect according to the provided ssh connection statement


0. Environment

windows 11 64 bit

premise:

There is an aws account (IAM), and an EC2 instance (virtual machine) already exists

1. Example of connection result

2. SSH connection ideas

First of all, you need to have an AWS account and a running EC2 instance, this part does not explain too much

Secondly, you need to ensure that it exists in your computer environment and run the SSH service (if not, the installation steps will be introduced below)

Finally, run the connection on the command line through the commands given on the EC2 instance interface

Official website reference documents:

Connect to a Linux instance from Linux or macOS using SSH - Amazon Elastic Compute Cloud

3. Specific steps

1) Install and run the ssh service

Reference: Add-WindowsCapability : Add-WindowsCapability failed. Error code = 0x800f0950 solution: Install ssh offline_Wen Ge Blog Blog-CSDN Blog

Download the ssh offline installation package on github, because I am windows64, so download this

Download address: Release PowerShell/Win32-OpenSSH (github.com)

After the download is complete, unzip the installation package to your custom path. After decompression, it looks like this

Then, the administrator runs cmd in this path

Note: If you are not an administrator, you will report an error

Administrator operation mode reference:

Then enter the path you just unzipped

First switch to the D drive [d:]

Then enter the corresponding path under the D disk [cd + your decompression path]

Then run the install

powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

After prompting that the installation is successful, the installation is complete

2) Start the ssh service

run command

net start sshd

Prompt 【start successfully】

3) Find the running EC2 instance on AWS, and connect according to the provided ssh connection statement

AWS click [Service], search or click EC2 to enter

Click to enter the running instance

Check the instance you want to connect to, and click [Connect]

Click Copy to copy the command [Example]

Note before connecting:

1. Before executing the command, you need to copy the key pair (.pem, which will be downloaded when the instance is created) of this EC2 instance to a local location (I copied it to: ~/key/), this location Need to remember, and then replace the double quotes in the example command.

2. The EC2 instance needs to open port 22. For the open port operation, please refer to the following blog:

EC2 opens port 22

Copy the command to the command line, run it on the command line after fine-tuning

Fine-tuning: I modified two places here

① The content in the quotation marks after ssh -i, this is the local key location, which is the place marked in red above, to copy this .pem key to the specified location

② "root" in front of the @ symbol, I changed it to [ubuntu], because my EC2 is a linux virtual machine, so I changed it to ubuntu, which usually refers to the user name

Finally, copy the modified command to the command line and press Enter to connect to the EC2 instance via SSH

At this point, the process of SSH connecting to the EC2 instance has been completed

--END--

Guess you like

Origin blog.csdn.net/qq_41539778/article/details/132667426