Connecting to an EC2 Instance on AWS via SSH Simplified

Connecting to an EC2 Instance on AWS via SSH Simplified

To connect to an EC2 instance using SSH, follow these steps:

  1. Ensure SSH Key File Permissions:

    • When you create an EC2 instance, AWS gives you a private key file (.pem). Download it and keep it secure.

    • Change its permissions so only you can read it:

        chmod 400 your-key.pem
      
  2. Find the Public DNS or IP of the Instance:

    • Go to the AWS EC2 Console > Instances.

    • Locate your instance and copy its Public DNS or Public IP.

  3. Connect Using SSH:

    • Use the SSH command to connect to the instance. Replace your-key.pem with your key file, and ec2-user@your-public-dns with your instance’s username and DNS/IP.

    • Example:

        ssh -i your-key.pem ec2-user@your-public-dns
      
    • Common usernames for EC2 instances:

      • Amazon Linux: ec2-user

      • Ubuntu: ubuntu

      • CentOS: centos

      • RHEL: ec2-user

      • SUSE: ec2-user

  4. Security Group:

    • Ensure the EC2 instance’s Security Group allows inbound SSH (port 22) from your IP address.
  5. Exit: If we want to remove connection to the instance, just type exit

Once these steps are completed, the SSH session should connect you directly to the EC2 instance.
"Thank you for reading! I hope this blog sparked new ideas and insights. If you have questions or thoughts, drop a comment below. Until next time, keep learning and growing!"
Reach out to me at linkedin.com/in/sruthipalle
Happy Coding😊