0
0
AWScloud~10 mins

Key pairs for SSH access in AWS - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - Key pairs for SSH access
Create Key Pair
AWS stores Public Key
User downloads Private Key
Launch EC2 Instance with Key Pair
User connects via SSH using Private Key
EC2 verifies Public Key
SSH Access Granted or Denied
This flow shows how AWS key pairs are created, stored, and used to securely connect to EC2 instances via SSH.
Execution Sample
AWS
aws ec2 create-key-pair --key-name MyKey --query 'KeyMaterial' --output text > MyKey.pem
chmod 400 MyKey.pem
ssh -i MyKey.pem ec2-user@ec2-instance-ip
Create a key pair in AWS and use the private key to SSH into an EC2 instance.
Process Table
StepActionAWS StateUser ActionResult
1Create key pair named 'MyKey'Public key saved in AWSPrivate key file downloadedKey pair ready for use
2Launch EC2 instance with 'MyKey'Instance stores public key for SSHWait for instance to startInstance ready for SSH
3User runs SSH command with private keyInstance receives SSH requestSSH client sends private keyInstance checks public key match
4Instance verifies key pair matchPublic key matches private keyConnection establishedSSH access granted
5If keys don't matchPublic key does not matchConnection attemptSSH access denied
💡 SSH access ends when key verification succeeds or fails.
Status Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Public Key (AWS)NoneStoredStoredStoredCheckedVerified or Rejected
Private Key (User)NoneDownloadedHeldUsed in SSHSent to InstanceUsed for Access
EC2 Instance StateStoppedStoppedRunning with KeyRunningRunningRunning
SSH ConnectionNoneNoneNoneAttemptedEstablished or DeniedEnded
Key Moments - 3 Insights
Why does AWS only store the public key and not the private key?
AWS stores only the public key for security reasons; the private key is kept only by the user to ensure only they can access the instance, as shown in execution_table step 1.
What happens if the private key used in SSH does not match the public key on the instance?
The instance denies SSH access because the keys don't match, as seen in execution_table step 5 where SSH access is denied.
Can you connect to an EC2 instance without the private key?
No, because the private key is required to prove your identity; without it, the instance will reject the connection (execution_table step 5).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step does the user download the private key?
AStep 3
BStep 1
CStep 2
DStep 4
💡 Hint
Check the 'User Action' column in execution_table step 1.
According to variable_tracker, what is the state of the EC2 instance after step 2?
ARunning with Key
BStopped
CRunning without Key
DTerminated
💡 Hint
Look at the 'EC2 Instance State' row after 'After Step 2' column.
If the private key is lost, what will happen during SSH connection according to execution_table?
ASSH access granted
BAWS regenerates the private key
CSSH access denied
DConnection succeeds without key
💡 Hint
Refer to execution_table step 5 where keys don't match.
Concept Snapshot
Key pairs are two linked keys: public (stored by AWS) and private (kept by user).
AWS uses the public key on EC2 instances to verify SSH connections.
Users connect via SSH using the private key file.
Private key must be kept safe; losing it means losing access.
AWS never stores the private key for security.
SSH access depends on matching key pairs.
Full Transcript
This visual execution shows how AWS key pairs enable secure SSH access to EC2 instances. First, a key pair is created; AWS stores the public key, and the user downloads the private key. When launching an EC2 instance, the public key is installed on it. To connect, the user uses the private key with SSH. The instance verifies the private key matches the stored public key. If they match, SSH access is granted; otherwise, it is denied. The private key must be kept safe by the user because AWS does not store it. Losing the private key means losing SSH access to the instance.