0
0
Linux CLIscripting~10 mins

SSH key generation (ssh-keygen) in Linux CLI - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - SSH key generation (ssh-keygen)
Start ssh-keygen command
Prompt for file location
Prompt for passphrase
Generate key pair files
Show key fingerprint and location
End
The ssh-keygen command runs, asks where to save the key, asks for a passphrase, then creates the key files and shows their info.
Execution Sample
Linux CLI
ssh-keygen -t rsa -b 2048
# User presses Enter to accept default file
# User enters passphrase or empty
# Key files created
Generates an RSA SSH key pair with 2048 bits, saving to default location, optionally secured by a passphrase.
Execution Table
StepActionUser InputSystem OutputResult
1Run ssh-keygen commandGenerating public/private rsa key pair.Starts key generation
2Prompt for file locationPress EnterEnter file in which to save the key (/home/user/.ssh/id_rsa):Default path chosen
3Prompt for passphraseEnter passphrase or emptyEnter passphrase (empty for no passphrase):Passphrase recorded or empty
4Prompt for passphrase confirmationRepeat passphrase or emptyEnter same passphrase again:Passphrase confirmed
5Generate keysYour identification has been saved in /home/user/.ssh/id_rsa Your public key has been saved in /home/user/.ssh/id_rsa.pub The key fingerprint is: SHA256:abc123... user@hostKey files created
6Exitssh-keygen process ends
💡 Key files created and saved, process ends
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
file_pathnone/home/user/.ssh/id_rsa/home/user/.ssh/id_rsa/home/user/.ssh/id_rsa/home/user/.ssh/id_rsa
passphrasenonenoneuser input or emptyconfirmed passphrase or emptystored securely
Key Moments - 2 Insights
Why does ssh-keygen ask twice for the passphrase?
It asks twice to make sure you typed the passphrase correctly, as shown in steps 3 and 4 in the execution table.
What happens if I just press Enter at the file location prompt?
Pressing Enter chooses the default file path for the key, as shown in step 2 where the default /home/user/.ssh/id_rsa is selected.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the file path chosen after step 2?
A/root/.ssh/id_rsa
B/etc/ssh/id_rsa
C/home/user/.ssh/id_rsa
DNo file chosen yet
💡 Hint
Check the 'User Input' and 'Result' columns in step 2 of the execution table.
At which step does ssh-keygen confirm the passphrase?
AStep 4
BStep 3
CStep 2
DStep 5
💡 Hint
Look for the step where the system asks to 'Enter same passphrase again' in the execution table.
If you enter a passphrase at step 3, what happens at step 5?
Assh-keygen asks for passphrase again
BKey files are created and passphrase protects the private key
CKey files are created without passphrase protection
Dssh-keygen exits without creating keys
💡 Hint
Refer to the 'Result' column at step 5 and the 'passphrase' variable in variable_tracker.
Concept Snapshot
ssh-keygen -t rsa -b 2048
- Runs key generation
- Prompts for file location (default if Enter)
- Prompts twice for passphrase
- Creates private and public key files
- Shows key fingerprint and location
Full Transcript
The ssh-keygen command starts and asks where to save the SSH key. If you press Enter, it uses the default location. Then it asks for a passphrase twice to confirm it. After that, it creates the private and public key files and shows their fingerprint and location. The process ends after keys are created. Variables like file path and passphrase change as you provide input. This helps secure your SSH connections.