What is Key Pair:
Generally, the public and private keys are known as a key pair. For the Amazon EC2 uses public–key cryptography to encrypt and decrypt login information. Public–key cryptography uses a public key to encrypt a piece of data, such as a password, then the recipient uses the private key to decrypt the data.
By default, options are available to create key pair in AWS-EC2 console while creating a new instance. If you would change the key pair example for ubuntu a user, make a new key pair in simple commands,
Before going to generate a key make sure that are you in ubuntu user login by command "id",
uid=1000(ubuntu) gid=1000(ubuntu) groups=1000(ubuntu),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),115(lpadmin),131(sambashare)
Assume that, key name would be ubuntuuser. Generate the key with "ssh-keygen -t rsa -b 2048 -v"
and when asked to enter file in which to save the key type name "ubuntuuser" hit enter without any password,
home@ubuntu:~$ ssh-keygen -t rsa -b 2048 -v
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_rsa): ubuntuuser
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ubuntuuser.
Your public key has been saved in ubuntuuser.pub.
The key fingerprint is:
The key's randomart image is:
| . =+E+|
| . + o. |
| = + . |
| S O . . |
| + + o |
| o . . |
| . |
Surely, you will get two files generated, one will be "ubuntuuser" and another one is "ubuntuuser.pub", rename the ubuntuuser to ubuntuuser.pem.
So you have two files are ubuntuuser.pub and ubuntuuser.pem,
Save this public key to your server ubuntu user ~/.ssh/authorized_keys file in EC2 instance,
You might make .pem file on your computer read-only sudo chmod 400 my-ubuntuuser.pem,
$ sudo chmod 400 my-ubuntuuser.pem
Finally, You could login without password
$ sudo ssh -i /path/to/ubuntuuser.pem email@example.com