For this example I am going to use EC2 t2.micro instance

while creating instance You’ll get option for key

→ either you generate on your own

→ or let the cloud service do it for you ✅

Example of creating new keypair for EC2

Screenshot 2023-07-04 at 4.13.47 PM.png

Screenshot 2023-07-04 at 4.14.01 PM.png

  1. Enter Name of key
  2. Select .pem for SSH
  3. Click Create key pair

→ Key will be downloaded

For SSH

  1. Open Terminal

  2. Run following command

    ssh -i (path to .pem ) ubuntu@ip address 
    
    1. Best practice: try to give path from the location where your terminal starts so that you don’t have to use cd each time you wants to connect and instead use ⬆️ arrow to use previous command
    2. use public ip address assigned to the instance

    for me it’ll be

    ssh -i ./Downloads/key1.pem [email protected]
    

    (ip will be changed after this blog is posted so no need to worry for me, so don’t try to use my ip)

    but now you’ll be promoted to chose yes or no

    type

    yes
    

    now you’ll be facing some error regarding file is too Open

    so cd to the file

    and run this command with your file name

    chmod 600 key.pem 
    

    → replace key with your file name

    cd
    ssh -i ./Downloads/key1.pem [email protected]
    

    Screenshot 2023-07-04 at 4.26.33 PM.png

    Initials will be changed with

    ubuntu@ip…….

    means you are successfully connected.

Get more at

How to SSH

1680500044834.jpeg

Author: Manav Rajani

Blogs link : Accurate