Tutorials · DevOps & Containers

How to Use SSH Keys Instead of Passwords for Network Devices and Servers

Passwords can be guessed, phished and reused. Create an SSH key pair, install the public key on gateways, edge servers and Linux hosts, then turn password logins off.

Beginner12 min6 steps

Before you start

  • A laptop with OpenSSH (built into Windows 10/11, macOS and Linux)
  • Admin access to the device or server
  • A second session open while you test, so you cannot lock yourself out

Step by step

  1. Create a key pair

    Ed25519 keys are short, fast and strong. Protect the private key with a passphrase: it never leaves your laptop.

    ssh-keygen -t ed25519 -C "alice@company-noc"
    # saved to ~/.ssh/id_ed25519 (private) and ~/.ssh/id_ed25519.pub (public)
    
  2. Install the public key

    Copy only the .pub file to the server. On devices without ssh-copy-id, paste the key into the admin page or into ~/.ssh/authorized_keys.

    ssh-copy-id -i ~/.ssh/id_ed25519.pub admin@10.1.10.20
    
  3. Test key login

    Open a new terminal and log in. You should be asked for the key passphrase, not the account password.

    ssh -i ~/.ssh/id_ed25519 admin@10.1.10.20
    
  4. Turn off password logins

    On Linux hosts and NavEdge edge servers, disable password and root logins in sshd_config, check the syntax and reload.

    sudo sed -i 's/^#\?PasswordAuthentication.*/PasswordAuthentication no/; s/^#\?PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
    sudo sshd -t && sudo systemctl reload ssh
    
  5. Use an SSH agent

    Load the key once per session instead of typing the passphrase for every device.

    eval "$(ssh-agent -s)"
    ssh-add ~/.ssh/id_ed25519
    
  6. Remove keys when people leave

    Every engineer gets their own key. Delete their line from authorized_keys on every host when they change role or leave.

Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.

Pro tips

  • Never share one private key between engineers.
  • Back up your private key in a password manager or hardware token, not in email or chat.
  • Hardware security keys (FIDO2) can hold SSH keys too: ssh-keygen -t ed25519-sk.