Purpose

I need to ssh to AWS Elastic beanstalk EC2 instance to install my Solr client upon it. But EBS automatically created the EC2 and configured everything for me, which skipped all usual setup steps. When I wanted to SSH to the instance, after typed

ssh -i ./myPwd.pem ec2-user@ec2-xx-xxx-xxx-xxx.us-west-1.compute.amazonaws.com

I got an

ssh: connect to host ec2-xx-xxx-xxx-xxx.us-west-1.compute.amazonaws.com port 22: Operation timed out

error in my terminal.

Reason & Solution

It happened because the default configuration of EBS skipped key pair and SSH setups.

Allow ssh and associate port for it

In the Security Group tab of EC2, you should find a default security group for EBS instances. Edit it by adding a new Rule for SSH:

SSH | tcp | 22 | 22 | 0.0.0.0/0 (Everywhere)

(For real world project, allowed IP should be depended on use case instead of 0.0.0.0)
Now, port 22 is ready for SSH connection.

Associate key pair

EC2 instance connection relies on key pair. Otherwise username and password are needed. To create key pair, go to EC2 corresponding region and create on in configuration.
To associate it with ECB instance, go to ECB panel => configuration => security => EC2 key pair, choose the right key pair and reboot.

Connect

AWS demands users to keep the private key safe. Otherwise, AWS will return

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for './news-finder.pem.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "./news-finder.pem.pem": bad permissions
Permission denied (publickey).

By changing permission to

chmod 400 myPwd.pem

You are free to connect to EC2 anywhere and whenever you want. Success message looks like

| ____| | __ _ ___| |_(_) ___| __ )  ___  __ _ _ __  ___| |_ __ _| | | __
|  _| | |/ _` / __| __| |/ __|  _ \ / _ \/ _` | '_ \/ __| __/ _` | | |/ /
| |___| | (_| \__ \ |_| | (__| |_) |  __/ (_| | | | \__ \ || (_| | |   <
|_____|_|\__,_|___/\__|_|\___|____/ \___|\__,_|_| |_|___/\__\__,_|_|_|\_\
                                       Amazon Linux AMI

This EC2 instance is managed by AWS Elastic Beanstalk. Changes made via SSH 
WILL BE LOST if the instance is replaced by auto-scaling. For more information 
on customizing your Elastic Beanstalk environment, see our documentation here: 
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html