How to Connect to AWS EC2 Using SSH?


How to Connect to AWS EC2 Using SSH?

In the realm of cloud computing, Amazon Web Services (AWS) stands as a formidable player, offering a myriad of services to facilitate seamless business operations. One such service is the Elastic Compute Cloud (EC2), a scalable virtual server in the cloud. Connecting to your EC2 instance securely is paramount, and one of the most effective ways to achieve this is through the use of Secure Shell (SSH). In this comprehensive guide, we will walk you through the step-by-step process of connecting to your AWS EC2 instance using SSH.

Step 1: Obtain Your Key Pair

Before diving into the SSH connection process, it is essential to have your key pair ready. During the EC2 instance creation, you have the option to either choose an existing key pair or create a new one. Ensure that you download the private key (.pem) securely and store it in a safe location.

Step 2: Set Permissions for Your Key Pair

To enhance security, it's crucial to set appropriate permissions for your private key. Open a terminal window and use the following command:

chmod 400 path/to/your-key.pem

Replace "path/to/your-key.pem" with the actual path to your private key file.

Step 3: Locate Your EC2 Instance Public IP

In the AWS Management Console, navigate to the EC2 dashboard and find the Public IP address of your instance.

Step 4: Open Your Terminal

Open your terminal or command prompt on your local machine. If you are using Windows, you may use a tool like PuTTY or Git Bash.

Step 5: Connect to Your EC2 Instance

Use the following SSH command to connect to your EC2 instance. Replace "your-key.pem" and "your-ec2-public-ip" with your actual key file and EC2 instance Public IP:

ssh -i path/to/your-key.pem ec2-user@your-ec2-public-ip

For example:

ssh -i ~/.ssh/my-key.pem ec2-user@54.123.456.789

Step 6: Success! You Are Now Connected

If everything is set up correctly, you should now be connected to your AWS EC2 instance using SSH. You will see a prompt similar to:

[ec2-user@ip-xxx-xx-xx-xx ~]$

Feel free to explore and manage your EC2 instance as needed.

More Examples:

  1. Copying Files to EC2:

To copy files from your local machine to the EC2 instance, you can use the scp command. For example:

scp -i path/to/your-key.pem local-file.txt ec2-user@your-ec2-public-ip:/path/to/destination/
  1. Terminating the Connection:

To terminate your SSH connection, simply type:

exit

Related Searches and Questions asked:

  • How to Do SSH in EC2?
  • How to Connect SSH to PuTTY from AWS?
  • How to Use SSH in Ubuntu?
  • How to Use SSH on AWS?
  • That's it for this topic, Hope this article is useful. Thanks for Visiting us.