Header Ads

How to SSH into EC2 Using Linux?

How to SSH into EC2 Using Linux

As a Linux user, one of the most common tasks you will encounter when working with Amazon Web Services (AWS) is to connect to your Elastic Compute Cloud (EC2) instance using SSH. In this article, we will walk you through the process of connecting to an EC2 instance using SSH from a Linux machine.

Prerequisites:

  • An active AWS account
  • A running EC2 instance
  • The public IP address or DNS of your EC2 instance
  • The private key (.pem) file associated with your EC2 instance

Step 1: Open your Terminal

To get started, open your terminal on your Linux machine. You can do this by pressing the "Ctrl+Alt+T" shortcut key or by searching for "Terminal" in your applications.

Step 2: Change directory to the location of your .pem file

Use the "cd" command to change your directory to the location where you saved the .pem file associated with your EC2 instance. For example, if your .pem file is located in your Downloads folder, you can use the following command:

cd ~/Downloads/

Step 3: Change the permissions of your .pem file

Before you can use your .pem file to connect to your EC2 instance, you need to change its permissions to 400. This can be done using the following command:

chmod 400 your-pem-file.pem

Replace "your-pem-file.pem" with the name of your .pem file.

Step 4: Connect to your EC2 instance using SSH

Now that your .pem file has the correct permissions, you can use the following command to connect to your EC2 instance:

ssh -i your-pem-file.pem ec2-user@ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com

Replace "your-pem-file.pem" with the name of your .pem file, and "ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com" with the public IP address or DNS of your EC2 instance.

Step 5: Verify your connection

If everything is working correctly, you should see a message similar to the following:

The authenticity of host 'ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com (xx.xx.xxx.xxx)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)?

Type "yes" to continue.

You should now be logged in to your EC2 instance.

More Examples:

  • If you want to connect to your EC2 instance as the root user, you can use the following command instead:
ssh -i your-pem-file.pem root@ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com
  • If you have multiple .pem files associated with your AWS account, you can specify which one to use by including the full path to the .pem file in the SSH command:
ssh -i /path/to/your-pem-file.pem ec2-user@ec2-xx-xx-xxx-xxx.compute-1.amazonaws.com

Related Searches and Questions asked:

  • How to Connect to AWS Server through SSH?
  • How Does SSH Work in AWS?
  • How to Generate SSH Key for Google Cloud Repository
  • What is Google Cloud Username for SSH?
  • That's it for this post. Keep practicing and have fun. Leave your comments if any.

    يتم التشغيل بواسطة Blogger.