There are 2 ways you can connect to EC2 instance:
- Go to EC2 -> Instances -> click on the instance -> Click the “Connect” button. That all.
- Using Putty and PuttyGen:
While creating an EC2 instance you would be asked to create a new key pair. A key pair is the combination of public key and private key. Public key is saved in the EC2 instance and private key is saved by customer. The private key file is having extension of *.pem, download the same and keep it a safe place, because you would be using the same to connect to the EC2 instance.
Using PuttyGen(PuTTYgen is an key generator tool for creating SSH keys for PuTTY) load the same private key and generate an putty specific private ssh key. Click the “Save private key” to generate the same, it will save in .ppk file.
Open Putty, copy the Public IPV4 address and paste it in the hostname. Go to Connection-> SSH -> Auth -> Private key file for authentication and browse the .ppk file. Hit “Open”. You will be asked to give the user name. Give “ec2-user“. You will be connected to EC2 now.
When you connect to the EC2, the default user will be:
ec2-user
Some popular commands to run on ec2:
hostname (this will display Private DNS)
ls
java -version
sudo yum update
sudo yum install java-1.8.0
whoami (will display ec2-user)
sudo -i (to move to the root directory)
alternatives –config java (prints all the java installed, and will ask you to choose an option to set as JAVA_HOME)