How to Setup SSH Key Authentication on VPS (Ubuntu/Debian)

 

How to Setup SSH Key Authentication on VPS (Ubuntu/Debian)

Secure your VPS by logging in with SSH Keys instead of passwords. This method works on Ubuntu, Debian, and similar Linux distributions.

Prerequisites

  • VPS with root SSH access.

  • A local Linux, macOS, or Windows with SSH client (e.g., PuTTY/Terminal).


Steps to Setup SSH Key Authentication

1. Generate SSH Key on Local Machine

Run the following on your local system:

ssh-keygen -t rsa -b 4096 -C "[email protected]"
  • Press Enter to accept default file location.

  • Optionally, set a passphrase.

The key will be saved in:

~/.ssh/id_rsa (private key)
~/.ssh/id_rsa.pub (public key)

2. Copy Public Key to VPS

Use ssh-copy-id (Linux/macOS) to upload the key:

ssh-copy-id root@your_server_ip

If ssh-copy-id is unavailable (Windows):
Manually copy the contents of id_rsa.pub and paste it into your VPS:

ssh root@your_server_ip
mkdir -p ~/.ssh
nano ~/.ssh/authorized_keys
# Paste the public key here, save, and exit.
chmod 600 ~/.ssh/authorized_keys

3. Test SSH Key Login

Disconnect and reconnect:

ssh root@your_server_ip

If successful, you won't be asked for a password.


4. (Optional) Disable Password Login

For enhanced security, follow this guide: Disable Password Login on VPS (Ubuntu/Debian)


Notes

  • Never share your private key (id_rsa).

  • Always keep a backup of your SSH key.


Related

  • setup ssh key authentication, ubuntu ssh key, debian ssh key, linux vps ssh setup, vps ssh key configuration, ssh key login, passwordless ssh login, ssh keygen tutorial
  • 0 Els usuaris han Trobat Això Útil
Ha estat útil la resposta?

Articles Relacionats

How to Request an rDNS (PTR) Update

If you need to update the rDNS (PTR) record for your VPS or dedicated server, please follow the...

Requesting mail access (Port 25)

By default, port 25 is blocked on all servers for outgoing email to prevent spam and abuse. If...

How to Add SSH Key for a New User on VPS (Ubuntu/Debian)

  How to Add SSH Key for a New User on VPS (Ubuntu/Debian) You can allow other users to access...

How to Disable Password Login on VPS (Ubuntu/Debian)

How to Disable Password Login for VPS (Ubuntu/Debian) Disable password login and enforce SSH key...

Powered by WHMCompleteSolution