DEV Community

Vishal Raju
Vishal Raju

Posted on

"Connecting to an EC2 Instance Using SSH: Easy Steps to Access Your Instance"

Image description

  1. Gather EC2 Instance Details
    Public DNS (or Public IP): Identify the Public DNS (or IP address) of your EC2 instance. You can find this in the AWS Management Console under the Instances section.
    Key Pair File (.pem): Ensure you have the private key (.pem file) that was used when launching the instance. If you don’t have it, you might need to create a new key pair and associate it with your instance.

  2. Set Permissions for Your Key Pair File
    Ensure that the permissions on your key pair file are set correctly to maintain security. In a terminal or command prompt, use the following command:
    bash
    Copy code
    chmod 400 /path/to/your-key-pair.pem
    Replace /path/to/your-key-pair.pem with the actual path to your key pair file.

  3. Open Your Terminal or Command Prompt
    Open a terminal window (Linux or macOS) or a command prompt (Windows).

  4. Connect Using SSH
    Use the ssh command to connect to your EC2 instance. The syntax is:

bash
Copy code
ssh -i /path/to/your-key-pair.pem ec2-user@your-instance-public-dns
Replace:
/path/to/your-key-pair.pem: Path to your .pem file.
ec2-user: Username for your instance (can vary by operating system; for example, ubuntu for Ubuntu instances).
your-instance-public-dns: Public DNS (or IP address) of your EC2 instance.
For example:

bash
Copy code
ssh -i ~/Downloads/your-key-pair.pem ec2-user@ec2-11-22-33-44.compute-1.amazonaws.com

  1. Authenticate and Connect
    If it’s your first time connecting to this instance, you may see a message about the authenticity of the host. Type yes to continue connecting.
    You should now be connected to your EC2 instance via SSH.

  2. Post-Connection Tasks
    Once connected, you can execute commands on your EC2 instance terminal just like you would on a local terminal.
    Troubleshooting Tips:
    Security Group Settings: Ensure that your EC2 instance’s security group allows SSH access (port 22) from your current IP address or IP range.
    Instance State: Verify that your EC2 instance is running and reachable over the network.

This detailed guide should help you connect to your EC2 instance securely using SSH.

Image description

Top comments (0)