Blog cover

SSH into an EC2 Instance

SSh into an ec2 instance

SSH into EC2 instance

Create a new keypair file while setting up the instance

Copy ssh -i aws-keypair-1.pem ubuntu@172.31.11.69

Change the permissions of the keypair file:

Copy chmod 600 aws-keypair-1.pem

Note that the IPv4 address used is the public one for that EC2 instance

Note that stopping the instance won't delete the EBS volume, and you will continue to be billed for it. However, terminating the instance should delete the associated EBS volume as well.

When you stop and start an EC2 instance, its public IP address changes. This means you won't be able to SSH into the instance using the same command as before. To overcome this, you can hibernate your instance, but be aware that this feature is not available for all instance types.

For a more secure and convenient way to access your EC2 instance, you can add your own public key to the instance's authorized keys. Here's how:

1. SSH into your EC2 instance using the .pem file.

2. Navigate to the ~/.ssh directory: cd ~/.ssh

3. Open the authorized_keys file: nano authorized_keys

4. Paste your public key at the end of the file, then save and exit.

After doing this, you can SSH into your instance using your own key pair, without needing the .pem file provided by AWS.

Important: Be cautious with the .pem file provided by AWS. If shared, it could allow others to access your EC2 instance. By using your own public key as described above, you enhance the security of your instance.