01 / 03

How to connect to an EC2 instance using SSH?

Difficulty: 4/10
SSH key management, Security groups, Network access

SSH Connection Process

Connecting via SSH is the standard method for managing Linux-based EC2 instances. You must have the private key (.pem file) generated during instance creation to authenticate securely.

SSH Command
Requirements
  1. 1

    Ensure your private key file has restricted permissions (chmod 400).

  2. 2

    The instance must have a public IP or be accessible via a bastion host.

  3. 3

    Port 22 must be open in the associated Security Group.

  4. 4

    Use the appropriate user for your AMI (e.g., ec2-user, ubuntu, admin).

Scenario Questions

0-2 years experience

  1. 1You have just launched a new t2.micro instance with a default security group. Walk me through the exact steps you would take to SSH into it from your laptop.
  2. 2If you try to SSH to the instance and get a 'Permission denied (publickey)' error, what are the first three things you would check?

2-5 years experience

  1. 1Our CI pipeline needs to run a script on a newly created EC2 instance via SSH, but the instance is in a private subnet with no public IP. How would you modify the setup to allow the script to connect securely?
  2. 2During a deployment we noticed that SSH connections to a fleet of instances started timing out after a recent security group change. Explain how you would diagnose and resolve the issue.
  3. 3We need to rotate the SSH key pair for an existing production instance without downtime. Describe the process you would follow.

5-8 years experience

  1. 1Design a secure, scalable solution for engineers to SSH into hundreds of EC2 instances across multiple VPCs, considering auditability and least‑privilege access.
  2. 2Our organization wants to enforce MFA for SSH access to EC2 instances. How would you integrate this requirement using AWS services and what trade‑offs would you consider?
  3. 3Explain the performance and security implications of using a bastion host versus AWS Systems Manager Session Manager for remote access.

8+ years experience

  1. 1We are planning to migrate a legacy on‑premises environment to AWS, and need a unified strategy for remote access to all workloads, including EC2, containers, and Lambda. How would you architect a cross‑team solution that balances security, compliance, and developer productivity?
  2. 2Discuss how you would evolve an existing SSH‑based access model to a zero‑trust architecture across multiple AWS accounts, including key management, logging, and incident response.
  3. 3What governance model would you put in place to manage SSH key lifecycle at scale, and how would you integrate it with CI/CD pipelines and audit frameworks?

Follow-up Questions

  • Can you walk me through how you'd automate key rotation for a large fleet?
  • What would you monitor to detect unauthorized SSH access attempts?
  • How does using Session Manager change your network security posture compared to a traditional bastion host?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.