SSH Key Setup
You're telling your Nginx server:
βHey, only let me in if I prove I have the private key that matches this public key.β
This is called SSH key-based authentication β it's more secure than using passwords.
When you generate an SSH key, you get two files:
id_rsaβ Private key (keep this secret, never share)id_rsa.pubβ Public key (can be shared, itβs safe)
They work like a lock and key:
- The public key goes on the server (like locking the door)
- The private key stays with you (like the key that unlocks the door)
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"- Creates a strong RSA key pair (public + private)
- Saves them in
~/.ssh/(unless you specify otherwise)
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 2222 root@192.168.0.100OR do it manually by copying the content of id_rsa.pub and pasting it in:
~/.ssh/authorized_keyson the server.
This tells the server:
"Hereβs my public key. If someone tries to SSH in, check if their private key matches this one."
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keysThese commands make sure:
- Your
.sshfolder is private - The
authorized_keysfile is readable only by the owner
Linux is picky about SSH security β wrong permissions = login wonβt work.
ssh -p 2222 root@192.168.0.100Now the server says:
"Okay, Iβve got your public key. Can you prove you own the private key?"
Your SSH client proves it silently using cryptography, and if it checks out β you're in β