Setting Up SSH Keys on Debian/Ubuntu Печать

  • 0

SSH keys provide a secure way to log in to your Linux server without using a password.

Generate SSH Key Pair

Run key generation on your own computer, not on the VPS. If a key already exists at the suggested path, do not overwrite it: reuse the existing key or choose a different filename. Keep the private key on your computer.

  1. Open terminal
  2. Run this command:
    ssh-keygen -t ed25519 -C "your_email@example.com"
  3. Press Enter to save the key in the default location
  4. Enter a passphrase (recommended) or leave empty

Copy Public Key to Server

Use either method:

Method 1: ssh-copy-id

ssh-copy-id username@server_ip

Method 2: Manual copy

  1. View your public key:
    cat ~/.ssh/id_ed25519.pub
  2. Connect to your server:
    ssh username@server_ip
  3. Create SSH directory:
    mkdir -p ~/.ssh
    chmod 700 ~/.ssh
  4. Add your key:
    echo "public_key_string" >> ~/.ssh/authorized_keys
    chmod 600 ~/.ssh/authorized_keys

Test Connection

ssh username@server_ip

Test from a new terminal while keeping the original session open. A key passphrase prompt is normal; a server account password prompt means key authentication did not complete. To test without password fallback, run:

ssh -o PreferredAuthentications=publickey -o PasswordAuthentication=no -o KbdInteractiveAuthentication=no username@server_ip

Use -i /path/to/private_key if you chose a non-default key filename. Verify the server fingerprint through a trusted route. Do not disable server password login until the key-only connection works and you have tested the VPS browser console.


Помог ли вам данный ответ?

« Назад

WHOIS Information

×
Loading WHOIS information...