DEV Community

Ashwarya
Ashwarya

Posted on Edited on

Setting Up an EC2 Instance and Logging In With MobaXterm

This one's shorter — just the actual process of creating an EC2 instance from the AWS console, and then getting into it from a Windows laptop using MobaXterm, plus the handful of things that actually go wrong when you try this for the first time.

Launching the instance

Nothing too dramatic here, it's mostly filling in a form on the EC2 page:

  1. Go to EC2 → Launch Instance.
  2. Give it a name.
  3. Pick an AMI — this is just the operating system image, Ubuntu and Amazon Linux are the common picks for practice.
  4. Pick an instance type — t2.micro is the usual free-tier choice for messing around.
  5. Create (or pick) a key pair. This downloads a .pem file to your laptop — this is the only copy AWS gives you, so don't lose it. If you do, there's no "re-download," you just have to make a new key pair.
  6. Leave network settings as default for a first try, but make sure "Allow SSH traffic" is ticked, since that's what lets you log in later at all.
  7. Hit Launch Instance.

Give it a minute to go from "pending" to "running" before trying to connect — it won't accept SSH connections until it's actually up.

Getting the pieces together before connecting

Two things you need in hand before opening MobaXterm:

  • The instance's public IPv4 address — on the instance's details page.
  • The .pem file you downloaded in step 5.

Worth knowing: if you ever stop and restart the instance (not terminate, just stop/start), the public IP usually changes unless you've attached an Elastic IP. So don't be surprised if an IP that worked yesterday doesn't work today — go grab the new one.

Connecting with MobaXterm

MobaXterm is basically the Windows equivalent of a terminal, and it can use .pem files directly — no need to convert them to .ppk like you would for old-school PuTTY.

  1. Open MobaXterm → Session → SSH.
  2. Remote host: paste the public IP.
  3. Specify username: ubuntu for an Ubuntu AMI, ec2-user for Amazon Linux. Getting this wrong is more common than you'd think.
  4. Go to the Advanced SSH Settings tab → tick Use private key → Browse → select your .pem file → OK.
  5. Click OK to connect. First time around, it'll ask if you trust the host — accept it, and you're in.

To close the session, just type exit or hit Ctrl+D.

If you're doing this from a regular terminal instead of MobaXterm (Mac/Linux), the equivalent is:

chmod 400 mykey.pem
ssh -i mykey.pem ubuntu@<public-ip>
Enter fullscreen mode Exit fullscreen mode

What actually goes wrong

A few things trip people up almost every time on the first attempt:

Connection timed out — nine times out of ten, this is the security group, not MobaXterm. Go to the instance's Security tab → inbound rules, and make sure port 22 (SSH) is open to your IP (or 0.0.0.0/0 for practice, though that's not something you'd leave open in anything real). If your IP changed since you set the rule — which happens a lot on home Wi-Fi — update it.

Authentication failed / wrong username — this one's just a wrong guess on ubuntu vs ec2-user. Check which AMI you actually launched and match the username to it.

Permission denied (publickey) — usually means you're pointing at the wrong .pem file, or using a key that doesn't match the instance it was created for. Each key pair only works with the instance(s) it was attached to at launch.

"Bad permissions" error on the key file — only happens on Mac/Linux terminals, not really in MobaXterm itself. SSH refuses to use a private key file that's too open, which is what the chmod 400 step above fixes.

It worked yesterday, not today — almost always the IP address changing after a stop/start, as mentioned above. Re-check the current public IP before assuming something's broken.

Session just freezes or hangs — sometimes it's a shaky network or a corporate VPN/firewall quietly blocking outbound port 22. Worth testing from a different network if nothing else explains it.

Quick mention: there's also a CLI way

Instead of clicking around the console every time, you can also manage EC2 from your own terminal using the AWS CLI — install it, run aws configure with your access key, secret key, and region, and then commands like aws ec2 describe-instances or aws s3 ls talk straight to your AWS account. It's worth knowing this exists even if console + MobaXterm is where most people start.

Takeaway

Almost every "it's not connecting" problem traces back to one of three things: the security group not allowing your IP on port 22, the wrong username for the AMI, or an IP address that quietly changed after a restart. Once you've hit each of these once, they stop being mysterious.

Top comments (0)