I have just launched my first Amazon EC2 instance and downloaded the .pem key pair file. I am trying to access the instance from my Windows machine using PuTTY, but I'm getting "Format error" and "Connection refused" messages. How do I convert the AWS key file into a format PuTTY recognizes, and which specific configuration settings (like Port or Auth) do I need to adjust to successfully log in?
3 answers
To connect via PuTTY, you first need to convert your .pem file to a .ppk file using the PuTTYgen tool, as PuTTY doesn't natively support the PEM format. Open PuTTYgen, load your .pem file, and click "Save private key." Once you have the .ppk, open PuTTY and enter your EC2 instance's Public IPv4 address in the Host Name field. Next, navigate to 'Connection' > 'SSH' > 'Auth' > 'Credentials' and browse for your .ppk file. Finally, ensure your EC2 Security Group allows inbound traffic on Port 22 for your specific IP address. When prompted for a username, use ec2-user for Amazon Linux, ubuntu for Ubuntu, or root depending on the AMI you selected.
I followed the conversion steps, but I am still getting a "Network error: Connection timed out." Could this be related to my local firewall or something within the AWS VPC settings?
Make sure you use the correct default username for your OS. If you try to log in as 'admin' on an Amazon Linux instance, it will reject the key even if your PuTTY setup is perfect.
Jennifer is spot on. I wasted an hour once because I forgot that Ubuntu instances require the username ubuntu specifically. Always double-check the AMI documentation for the default user!
It's almost certainly a networking issue, David. Check your AWS Security Group and ensure there is an "Inbound Rule" for SSH on Port 22. Also, verify that your EC2 instance is in a Public Subnet with an attached Internet Gateway. If you are behind a corporate firewall, Port 22 might be blocked locally, in which case you might need to use the "EC2 Instance Connect" browser-based terminal instead of a standalone SSH client like PuTTY.