Connecting to an EC2 instance doesn’t have to be complicated. This tutorial walks you through how to establish a secure SSH connection to a public EC2 instance using MobaXterm, with clear steps and best practices.
Overview:
- Goal: Connect via SSH to an EC2 instance with a public IP using a .pem key in MobaXterm.
- Approach: Simple steps, no CLI required — perfect for demos or quick tests.
- Best practices: Security group rules and correct username depending on the AMI.
Step‑by‑Step with MobaXterm
Step 1. Open MobaXterm Launch MobaXterm (Portable or installed) to access the main panel.
Step 2. Create a new session Click Session → SSH to start configuring the connection.
Step 3. Configure host and user
- Host: Enter the EC2 public IP or Elastic IP.
- Username: Use the correct AMI user (e.g., ec2-user for Amazon Linux, ubuntu for Ubuntu).
Step 4. Load the private key (.pem)
- Check Use private key and select your .pem file.
- Tip: MobaXterm usually accepts .pem directly. If not, convert to .ppk with PuTTYgen.
Step 5. Name the session (optional) In Bookmark settings, give the session a descriptive name (e.g., “EC2‑Prod‑VA”).
Step 6. Accept the host fingerprint On first connection, MobaXterm will show the host key fingerprint. Click Accept to trust the server.
Step 7. Connect and verify Click OK/Connect. Once inside, run whoami and hostname to confirm access.
Quick Troubleshooting
- Permission denied (publickey): Check the correct SSH Username and ensure the .pem matches the instance key pair.
- Timeout: Verify port 22 is open in the Security Group and that the instance has a public IP.
- Wrong user: Adjust the username according to the AMI.
Best Practices
- Restrict port 22 to your IP only — avoid 0.0.0.0/0 in production.
- Use Elastic IPs for stable addressing.
- Name your sessions in MobaXterm for clarity across environments.
✅ With these steps, connecting to a public EC2 instance using MobaXterm is straightforward, secure, and repeatable for demos or production environments.
⚠️ Note on Public EC2 Instances
Connecting to a public EC2 instance is useful for demos and quick tests, but it’s not recommended for production. Public IPs expose your server directly to the internet, which increases security risks if not managed properly.
✅ Best Practice: Use private subnets, bastion hosts, or AWS Systems Manager Session Manager for secure access.
👉 In my next post, I’ll cover how to connect to an EC2 Private Instance, following best practices for secure architectures.







Top comments (0)