SSH Key Files Deep Dive

@amitmund June 25, 2026

SSH Topic

Level: Intermediate → Advanced

SSH works because of a collection of files stored on both the client and server.

Most SSH problems are caused by:

Wrong File
Wrong Permissions
Wrong Ownership
Missing Keys
Misconfigured Files

Understanding every SSH file is critical for:

  • Linux Administration
  • DevOps
  • Cloud Engineering
  • Security Engineering
  • Production Troubleshooting

This topic provides a deep dive into every important SSH key-related file.


Table of Contents

  1. SSH File Overview
  2. SSH Directory Structure
  3. id_rsa
  4. id_ed25519
  5. .pub Files
  6. authorized_keys
  7. known_hosts
  8. SSH Config File
  9. Host Keys
  10. File Permissions
  11. Key Protection
  12. Key Lifecycle
  13. Internal Architecture
  14. File Relationships
  15. Commands
  16. Code Examples
  17. Real-World Examples
  18. Production Examples
  19. Common Mistakes
  20. Troubleshooting
  21. Security Notes
  22. Interview Questions
  23. Hands-On Labs
  24. Exercises
  25. Quiz

1. SSH File Overview

SSH uses multiple files.

Each file serves a specific purpose.


Client Side Files

~/.ssh/id_rsa

~/.ssh/id_ed25519

~/.ssh/id_rsa.pub

~/.ssh/id_ed25519.pub

~/.ssh/known_hosts

~/.ssh/config

Server Side Files

~/.ssh/authorized_keys

/etc/ssh/ssh_host_*

High-Level Diagram

Client
 |
 +-- Private Keys
 |
 +-- Public Keys
 |
 +-- Config
 |
 +-- known_hosts
 |
SSH Connection
 |
Server
 |
 +-- authorized_keys
 |
 +-- Host Keys

2. SSH Directory Structure

Default SSH directory:

~/.ssh

Example

ls -la ~/.ssh

Output:

authorized_keys
config
id_ed25519
id_ed25519.pub
known_hosts

Typical Structure

~/.ssh/
|
+-- id_rsa
+-- id_rsa.pub
+-- id_ed25519
+-- id_ed25519.pub
+-- authorized_keys
+-- known_hosts
+-- config

Meaning

Private Keys

Public Keys

Trusted Servers

Connection Settings

3. id_rsa

One of the traditional SSH private key files.


What is id_rsa?

RSA Private Key

Location

~/.ssh/id_rsa

Generate

ssh-keygen -t rsa -b 4096

Example

cat ~/.ssh/id_rsa

Output:

-----BEGIN OPENSSH PRIVATE KEY-----

Important

Contains:

Secret Authentication Material

NEVER

Share

Email

Upload

Commit to Git

Diagram

id_rsa
   |
Private Key
   |
Authentication

4. id_ed25519

Modern SSH private key.


Location

~/.ssh/id_ed25519

Generate

ssh-keygen -t ed25519

Why Preferred?

Smaller

Faster

More Secure

Modern

Example

ls ~/.ssh/id_ed25519

Diagram

id_ed25519
     |
Private Key
     |
Authentication

Recommendation

Use:

ED25519

for new environments.


5. .pub Files

Public key files.


Examples

id_rsa.pub

id_ed25519.pub

Purpose

Contain:

Public Key

View File

cat ~/.ssh/id_ed25519.pub

Example Output

ssh-ed25519 AAAAC3Nza...

Safe To Share?

Yes

Usage

Copied into:

authorized_keys

Relationship

Private Key
      |
Generate
      |
Public Key (.pub)

Diagram

id_ed25519
      |
Generate
      |
id_ed25519.pub

6. authorized_keys

One of the most important SSH files.


Location

~/.ssh/authorized_keys

Purpose

Stores public keys allowed to log in.


Example

cat ~/.ssh/authorized_keys

Output:

ssh-ed25519 AAAAC3Nza...
ssh-rsa AAAAB3Nza...

Authentication Logic

Client Public Key
        |
authorized_keys
        |
Match Found?

Match

Allow Login

No Match

Permission denied (publickey)

Diagram

Public Key
      |
authorized_keys
      |
Authentication

Common Usage

ssh-copy-id user@server

adds keys automatically.


7. known_hosts

Stores trusted server identities.


Location

~/.ssh/known_hosts

Purpose

Prevents:

Man-in-the-Middle Attacks

Example

cat ~/.ssh/known_hosts

Sample Entry

server.example.com ssh-ed25519 AAAA...

What Happens?

When connecting:

Server Presents Host Key

SSH checks:

known_hosts

Diagram

Server Host Key
        |
known_hosts
        |
Match?

Match

Connection Continues

No Match

Host Key Warning

Common Warning

REMOTE HOST IDENTIFICATION
HAS CHANGED

8. SSH Config File

Personal SSH configuration.


Location

~/.ssh/config

Purpose

Store connection settings.


Example

Host webserver
    HostName 192.168.1.100
    User admin

Connect Using

ssh webserver

Without Config

ssh [email protected]

Benefits

Short Commands

Multiple Keys

Custom Ports

Automation

Example Configuration

Host prod
    HostName 10.0.0.50
    User admin
    Port 2222
    IdentityFile ~/.ssh/id_ed25519_prod

Diagram

ssh prod
    |
config
    |
Connection Details

9. Host Keys

Host keys identify servers.


Different From User Keys

User Keys:

Identify User

Host Keys:

Identify Server

Location

/etc/ssh/

Examples

ssh_host_rsa_key

ssh_host_ed25519_key

ssh_host_ecdsa_key

View

ls /etc/ssh/ssh_host_*

Purpose

Used during:

Host Verification

Diagram

Server
 |
Host Key
 |
Client Verification
 |
known_hosts

Host Key Files

Private Host Key

Public Host Key

Example

ssh_host_ed25519_key

ssh_host_ed25519_key.pub

10. File Permissions

SSH is extremely strict.


Why?

Protects sensitive keys.


Check Permissions

ls -la ~/.ssh

Recommended

Directory:

chmod 700 ~/.ssh

Private Key:

chmod 600 ~/.ssh/id_ed25519

Public Key:

chmod 644 ~/.ssh/id_ed25519.pub

authorized_keys:

chmod 600 ~/.ssh/authorized_keys

Table

File Permission
~/.ssh 700
id_ed25519 600
id_rsa 600
authorized_keys 600
.pub files 644

Common Error

Permission denied (publickey)

because permissions are too open.


11. Key Protection

Private keys must be protected.


Threats

Key Theft

Malware

Unauthorized Access

Accidental Exposure

Best Practices


Use Passphrases

ssh-keygen -p

Secure Backups

Store encrypted copies.


Limit Access

chmod 600

Separate Keys

Personal

Work

Production

Use Hardware Security Keys

Examples:

YubiKey

Nitrokey

Protection Diagram

Private Key
      |
Passphrase
      |
Filesystem Permissions
      |
Encrypted Backup

12. Key Lifecycle

Keys have a lifecycle.


Stage 1

Generation

ssh-keygen

Stage 2

Deployment

ssh-copy-id

Stage 3

Usage

ssh user@server

Stage 4

Rotation

Replace old key.


Stage 5

Revocation

Remove from:

authorized_keys

Stage 6

Retirement

Delete securely.


Lifecycle Diagram

Generate
    |
Deploy
    |
Use
    |
Rotate
    |
Revoke
    |
Retire

Why Rotation Matters

Reduces risk if key is exposed.


13. Internal Architecture

Client
 |
 +-- id_ed25519
 |
 +-- id_ed25519.pub
 |
 +-- known_hosts
 |
 +-- config
 |
SSH
 |
Server
 |
 +-- authorized_keys
 |
 +-- Host Keys

14. File Relationships

id_ed25519
      |
Generates
      |
id_ed25519.pub
      |
Copied To
      |
authorized_keys

Host Key
      |
Stored In
      |
known_hosts

config
      |
Controls
      |
SSH Behavior

15. Commands

List SSH Files:

ls -la ~/.ssh

View Public Key:

cat ~/.ssh/id_ed25519.pub

View Authorized Keys:

cat ~/.ssh/authorized_keys

View Known Hosts:

cat ~/.ssh/known_hosts

Edit Config:

nano ~/.ssh/config

Fix Permissions:

chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
chmod 600 ~/.ssh/authorized_keys

16. Code Examples

Generate Key:

ssh-keygen -t ed25519

Copy Key:

ssh-copy-id user@server

Custom Host:

Host prod
    HostName 10.0.0.50
    User admin

Connect:

ssh prod

17. Real-World Examples

Developer Laptop

~/.ssh/id_ed25519

used for:

GitHub
GitLab
Servers

System Administrator

Separate Production Key

stored as:

id_ed25519_prod

18. Production Examples

Cloud Infrastructure

Admin Laptop
 |
SSH Keys
 |
EC2 Instances

Enterprise Servers

authorized_keys
 |
Thousands of Logins

Kubernetes Nodes

Node SSH Access
 |
Managed Via Keys

19. Common Mistakes


Mistake 1

Committing private keys to Git.


Mistake 2

Wrong permissions.


Mistake 3

Deleting authorized_keys accidentally.


Mistake 4

Ignoring host key warnings.


Mistake 5

Using one key for everything.


Mistake 6

Not rotating old keys.


20. Troubleshooting


Permission Denied

Check:

ls -la ~/.ssh

Key Not Found

Check:

ls ~/.ssh

Host Key Changed

Inspect:

cat ~/.ssh/known_hosts

Config Ignored

Validate:

ssh -G hostname

Server Rejecting Login

Inspect:

cat ~/.ssh/authorized_keys

21. Security Notes

Never share:

Private Keys

Always use:

Passphrases

Protect:

authorized_keys

known_hosts

Rotate keys regularly.


Audit SSH files periodically.


Use separate keys for different environments.


22. Interview Questions

Q1

What is authorized_keys used for?

Answer:

Stores public keys allowed to log in.

Q2

What is known_hosts?

Answer:

Stores trusted server host keys.

Q3

Difference between host key
and user key?

Answer:

Host key identifies server.
User key identifies user.

Q4

Where is SSH config stored?

Answer:

~/.ssh/config

Q5

Typical permission for
private key file?

Answer:

600

23. Hands-On Labs


Lab 1

Inspect SSH Directory

ls -la ~/.ssh

Lab 2

View Public Key

cat ~/.ssh/id_ed25519.pub

Lab 3

Inspect known_hosts

cat ~/.ssh/known_hosts

Lab 4

Create SSH Config

nano ~/.ssh/config

Add:

Host test
    HostName 192.168.1.100
    User admin

Lab 5

Verify Permissions

ls -la ~/.ssh

Lab 6

Inspect Host Keys

ls /etc/ssh/ssh_host_*

24. Exercises

Exercise 1

Explain the purpose of:
authorized_keys

Exercise 2

Explain the role of:
known_hosts

Exercise 3

Describe SSH host keys.

Exercise 4

List recommended SSH permissions.

Exercise 5

Describe the SSH key lifecycle.

25. Quiz

Question 1

Which file stores allowed public keys?

A. known_hosts
B. authorized_keys
C. config
D. passwd

Answer:

B

Question 2

Which file stores trusted servers?

A. authorized_keys
B. shadow
C. known_hosts
D. config

Answer:

C

Question 3

Typical permission for private key?

A. 777
B. 755
C. 644
D. 600

Answer:

D

Question 4

Host keys identify:

A. Users
B. Servers
C. Groups
D. Processes

Answer:

B

Question 5

Default SSH configuration file?

A. ~/.ssh/config
B. ~/.ssh/settings
C. /etc/passwd
D. /var/log/auth.log

Answer:

A

Summary

You should now understand:

✓ id_rsa

✓ id_ed25519

✓ Public Key Files (.pub)

✓ authorized_keys

✓ known_hosts

✓ SSH Config File

✓ Host Keys

✓ File Permissions

✓ Key Protection

✓ Key Lifecycle

✓ Relationships Between All SSH Files

✓ Production-Level SSH File Management

Next Topic:

Topic #10 — SSH Client Configuration

~/.ssh/config

Host Aliases

IdentityFile

Port

User

ForwardAgent

ProxyJump

Match Blocks

Include Directives

Advanced Client Configurations
0 Likes
67 Views
0 Comments

Filters

No filters available for this view.

Reset All