SSH Key Login
SSH keys are safer than password login. Instead of typing your server password, your computer proves your identity with a private key.
Generate a key on Windows
Section titled “Generate a key on Windows”Option 1: PuTTYgen
Section titled “Option 1: PuTTYgen”- Open PuTTYgen.
- Select ED25519 if available. Otherwise use RSA with at least 4096 bits.
- Click Generate and move your mouse until the key is created.
- Add a strong passphrase.
- Click Save private key and store it somewhere safe.
- Copy the public key text from the top box.
Option 2: Windows Terminal
Section titled “Option 2: Windows Terminal”Open PowerShell or Windows Terminal and run:
ssh-keygen -t ed25519 -C "your-email@example.com"Press Enter to accept the default path and set a strong passphrase.
Your public key is usually stored here:
C:\Users\<YourUser>\.ssh\id_ed25519.pubAdd the public key to the server
Section titled “Add the public key to the server”Connect to your server with PuTTY or another SSH client, then create the SSH folder:
mkdir -p ~/.sshchmod 700 ~/.sshOpen the authorized keys file:
nano ~/.ssh/authorized_keysPaste your public key into the file. It should be one line starting with something like ssh-ed25519 or ssh-rsa.
Save the file, then fix permissions:
chmod 600 ~/.ssh/authorized_keysTest key login
Section titled “Test key login”Open a new PuTTY session and configure the private key:
- Go to Connection → SSH → Auth → Credentials.
- Select your private key file.
- Go back to Session.
- Enter the server IP and save the session.
- Click Open.
Keep your old SSH session open while testing. If the key login does not work, you can still fix the configuration from the old session.
Disable password login
Section titled “Disable password login”Only do this after key login works.
Open the SSH server config:
nano /etc/ssh/sshd_configSet or add these lines:
PasswordAuthentication noPubkeyAuthentication yesPermitRootLogin prohibit-passwordRestart SSH:
systemctl restart sshThen open a new SSH connection and confirm key login still works.
Backup your private key
Section titled “Backup your private key”Store your private key somewhere safe, such as a password manager. Anyone with your private key and passphrase can access your server.
Never upload your private key to public websites, Discord, GitHub, or support tickets.