{"id":4160,"date":"2023-11-04T23:14:06","date_gmt":"2023-11-04T23:14:06","guid":{"rendered":"http:\/\/localhost:10003\/accessing-your-ec2-instances-using-ssh\/"},"modified":"2023-11-05T05:47:58","modified_gmt":"2023-11-05T05:47:58","slug":"accessing-your-ec2-instances-using-ssh","status":"publish","type":"post","link":"http:\/\/localhost:10003\/accessing-your-ec2-instances-using-ssh\/","title":{"rendered":"Accessing your EC2 instances using SSH"},"content":{"rendered":"
Amazon Elastic Compute Cloud (EC2) is a web service that offers resizable compute capacity in the cloud. It gives users the ability to quickly and easily launch virtual machines called instances, which can be used to run applications and workloads. When working with EC2 instances, it is often necessary to access them over a secure shell (SSH) connection for configuration, maintenance, and troubleshooting.<\/p>\n
In this tutorial, we will be taking a closer look at how to access your EC2 instances using SSH. We\u2019ll go through each step of the process, from creating a key pair to logging in to your instance. This tutorial assumes that you already have an AWS account and have created an EC2 instance.<\/p>\n
The first step in accessing your EC2 instance using SSH is to create a key pair. A key pair is a set of public and private keys that are used to securely access your instance. Here\u2019s how to create a key pair:<\/p>\n
Navigate to the EC2 dashboard.<\/p>\n<\/li>\n
In the navigation pane, click on \u201cKey Pairs.\u201d<\/p>\n<\/li>\n
Click the \u201cCreate Key Pair\u201d button.<\/p>\n<\/li>\n
Enter a name for your key pair.<\/p>\n<\/li>\n
Click the \u201cCreate\u201d button.<\/p>\n<\/li>\n
Your private key file will automatically be downloaded to your computer. Be sure to store it in a safe location, as you\u2019ll need it to access your EC2 instance.<\/p>\n<\/li>\n<\/ol>\n
Alternatively, you can create a key pair using the AWS Command Line Interface (CLI). Here\u2019s the command to create a key pair:<\/p>\n
aws ec2 create-key-pair --key-name my-key-pair --query 'KeyMaterial' --output text > my-key-pair.pem\n<\/code><\/pre>\nThis command creates a new key pair with the name \u201cmy-key-pair\u201d and stores the private key in a file called \u201cmy-key-pair.pem\u201d on your local computer.<\/p>\n
Setting Up Security Group Rules<\/h3>\n
Before you can access your instance using SSH, you need to make sure that inbound traffic is allowed on the port you\u2019ll be using for SSH. By default, SSH traffic uses port 22.<\/p>\n
Here\u2019s how to add an inbound rule to your security group:<\/p>\n
\n- Log in to the AWS Management Console.<\/p>\n<\/li>\n
- \n
Navigate to the EC2 dashboard.<\/p>\n<\/li>\n
- \n
In the navigation pane, click on \u201cSecurity Groups.\u201d<\/p>\n<\/li>\n
- \n
Select the security group associated with your instance.<\/p>\n<\/li>\n
- \n
Click on the \u201cInbound\u201d tab.<\/p>\n<\/li>\n
- \n
Click the \u201cEdit\u201d button.<\/p>\n<\/li>\n
- \n
Click the \u201cAdd Rule\u201d button.<\/p>\n<\/li>\n
- \n
Under \u201cType,\u201d select \u201cSSH.\u201d<\/p>\n<\/li>\n
- \n
Under \u201cSource,\u201d select \u201cMy IP\u201d to allow inbound traffic from your IP address.<\/p>\n<\/li>\n
- \n
Click the \u201cSave\u201d button.<\/p>\n<\/li>\n<\/ol>\n
You now have a security group rule that permits inbound SSH traffic to your instance.<\/p>\n
Accessing Your Instance Using SSH<\/h3>\n
Now that you\u2019ve created a key pair and set up security group rules, you\u2019re ready to access your EC2 instance using SSH.<\/p>\n
Here\u2019s how to SSH into your instance:<\/p>\n
\n- Open your terminal or command prompt.<\/p>\n<\/li>\n
- \n
Navigate to the directory where your private key file is stored.<\/p>\n<\/li>\n
- \n
Change the permissions of your private key file to 400:<\/p>\n<\/li>\n<\/ol>\n
chmod 400 my-key-pair.pem\n<\/code><\/pre>\n\n- Use the following command to connect to your instance:<\/li>\n<\/ol>\n
ssh -i my-key-pair.pem ec2-user@public-dns-name\n<\/code><\/pre>\nReplace \u201cmy-key-pair.pem\u201d with the name of your private key file and \u201cpublic-dns-name\u201d with the public DNS name of your instance. The \u201cec2-user\u201d is the default username for Amazon Linux instances.<\/p>\n
If you\u2019re using a different operating system, the default username may be different. Here\u2019s a list of default usernames for different operating systems:<\/p>\n
\n- Amazon Linux: ec2-user<\/li>\n
- Ubuntu: ubuntu<\/li>\n
- RHEL and CentOS: ec2-user or root<\/li>\n
- SUSE: ec2-user or root<\/li>\n
- Windows: Administrator<\/li>\n<\/ul>\n
Once you\u2019ve successfully connected to your instance using SSH, you\u2019ll be able to execute commands and perform administrative tasks.<\/p>\n
Troubleshooting SSH Connection Issues<\/h3>\n
If you\u2019re having trouble connecting to your instance using SSH, here are a few things you can try:<\/p>\n
\n- Verify that your security group rules allow inbound traffic on port 22.<\/li>\n
- Check that your key pair is correctly configured and stored in the correct directory.<\/li>\n
- Check that your private key file has the correct permissions (400).<\/li>\n
- Verify that the public DNS name of your instance is correct.<\/li>\n
- Check that your instance is running and in a state that allows SSH connections.<\/li>\n
- Try connecting again after a few moments in case there was a network issue.<\/li>\n<\/ul>\n
By following these steps, you should be able to access your EC2 instance using SSH.<\/p>\n
Conclusion<\/h3>\n
Accessing your EC2 instances using SSH is an essential skill for anyone working with Amazon Web Services. By creating a key pair, setting up security group rules, and establishing a secure shell connection, you can quickly and easily perform administrative tasks and troubleshoot issues on your instances.<\/p>\n
This tutorial covered the basics of accessing your EC2 instances using SSH. We looked at how to create a key pair, set up security group rules, and troubleshoot common connection issues. If you follow these steps, you should be able to access your EC2 instances with ease.<\/p>\n","protected":false},"excerpt":{"rendered":"
Amazon Elastic Compute Cloud (EC2) is a web service that offers resizable compute capacity in the cloud. It gives users the ability to quickly and easily launch virtual machines called instances, which can be used to run applications and workloads. When working with EC2 instances, it is often necessary to Continue Reading<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[317,30,1510,1512,1511,1509,1508],"yoast_head":"\nAccessing your EC2 instances using SSH - Pantherax Blogs<\/title>\n\n\n\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n