How To Configure SSH Key Authentication On Ubuntu VPS Server Skriv ut

  • ssh key authentication ubuntu vps, ubuntu ssh keys setup, secure ssh login linux, linux vps hardening, ssh public key authentication, ubuntu server security, vps ssh guide, secure ssh access
  • 89112

SSH key authentication is one of the most effective ways to secure Linux VPS servers.

Unlike passwords,
SSH keys provide:

  • stronger security
  • encrypted authentication
  • protection against brute-force attacks
  • safer remote access

In this guide,
you will learn how to configure SSH key authentication on an Ubuntu VPS server step-by-step.


What Is SSH Key Authentication?

SSH key authentication uses:

  • Public Key
  • Private Key

instead of traditional passwords.

Authentication occurs using cryptographic keys,
making login significantly more secure.

SSH keys are widely used in:

  • production servers
  • cloud environments
  • DevOps infrastructure
  • enterprise hosting

Why Use SSH Keys?

SSH keys provide:

  • stronger security
  • passwordless login
  • protection against brute-force attacks
  • improved authentication
  • safer server management

SSH key authentication is recommended for all Linux VPS environments.


Prerequisites

Before starting,
ensure you have:

  • Ubuntu VPS server
  • SSH access enabled
  • root or sudo privileges
  • terminal access on your local computer

Recommended operating system:

 
Ubuntu 22.04 LTS
 

Step 1 — Generate SSH Key Pair

On your local computer,
generate SSH keys.

Command:

 
ssh-keygen
 

Press:

 
Enter
 

to accept default location.

Example key files created:

 
~/.ssh/id_rsa
~/.ssh/id_rsa.pub
 

Step 2 — View Public Key

Display your public key.

Command:

 
cat ~/.ssh/id_rsa.pub
 

Copy the entire output.


Step 3 — Login To VPS

Connect to your VPS using password authentication.

Command:

 
ssh root@your-server-ip
 

Example:

 
ssh root@192.168.1.10
 

Step 4 — Create SSH Directory

Create SSH directory.

Command:

 
mkdir -p ~/.ssh
 

Set permissions.

Command:

 
chmod 700 ~/.ssh
 

Step 5 — Add Public Key

Open authorized keys file.

Command:

 
nano ~/.ssh/authorized_keys
 

Paste your copied public key.

Save the file.


Step 6 — Set File Permissions

Secure the authorized keys file.

Command:

 
chmod 600 ~/.ssh/authorized_keys
 

This prevents unauthorized access.


Step 7 — Test SSH Key Login

Open a NEW terminal window.

Connect normally.

Command:

 
ssh root@your-server-ip
 

If configured correctly,
you should log in without entering a password.


Step 8 — Verify Active Authentication

Check SSH logs.

Command:

 
journalctl -u ssh
 

Successful logins will be recorded.


Important SSH Key Files

Private key:

 
~/.ssh/id_rsa
 

Public key:

 
~/.ssh/id_rsa.pub
 

Authorized keys file:

 
~/.ssh/authorized_keys
 

Important SSH Commands

Generate Key Pair

 
ssh-keygen
 

View Public Key

 
cat ~/.ssh/id_rsa.pub
 

Connect Using SSH

 
ssh root@server-ip
 

Copy SSH Key Automatically

 
ssh-copy-id root@server-ip
 

Restart SSH Service

 
systemctl restart ssh
 

Common SSH Key Errors

Permission Denied (Public Key)

Possible causes:

  • incorrect permissions
  • missing public key
  • wrong user account

Verify:

 
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
 

SSH Key Not Being Used

Check:

 
sshd -t
 

Restart SSH service:

 
systemctl restart ssh
 

Lost Private Key

Without the private key,
authentication will fail.

Always store your private key securely and maintain backups.


Additional Security Recommendations

For stronger VPS security:

  • disable password authentication
  • change SSH port
  • disable root login
  • install Fail2Ban
  • configure firewall rules
  • use strong SSH passphrases

Security should always be layered.


Why Businesses Use SSH Keys

Businesses use SSH key authentication because it provides:

  • stronger access control
  • improved security
  • encrypted authentication
  • reduced attack surfaces
  • better compliance

SSH keys are standard practice for modern infrastructure.


Why Choose DJ Technologies VPS Hosting

DJ Technologies Linux VPS hosting provides:

  • enterprise virtualization
  • NVMe SSD infrastructure
  • premium low latency network
  • advanced infrastructure security
  • scalable cloud resources
  • optimized VPS environments
  • DDoS protection
  • 24×7 technical support

Our VPS infrastructure is optimized for:

  • secure Linux hosting
  • enterprise workloads
  • cloud infrastructure
  • SaaS applications
  • business-critical systems

Final Thoughts

SSH key authentication is one of the most important Linux VPS security practices.

By implementing:

  • SSH keys
  • secure permissions
  • authentication hardening
  • layered security

you can significantly improve:

  • server security
  • access control
  • infrastructure stability
  • protection against attacks
  • overall VPS reliability.

Var dette svaret til hjelp?

« Tilbake

Powered by WHMCompleteSolution