Passwordless SSH on Ubuntu: Secure Setup Guide
Configuring password-free SSH login on an Ubuntu server is a foundational practice for improving both security and operational efficiency.
By leveraging asymmetric cryptography, you eliminate password-based attacks while enabling seamless automation and remote access.
๐ Core Concept: Asymmetric Encryption #
SSH key authentication is based on a key pair:
-
Public Key (
id_rsa.pub)
Stored on the server โ acts like a lock -
Private Key (
id_rsa)
Kept securely on your local machine โ acts like the key
Only a matching private key can unlock access, making brute-force attacks virtually ineffective.
โ๏ธ Step-by-Step Setup #
Step 1: Create a Dedicated User (Server-Side) #
Use adduser for a complete and interactive setup:
server$ sudo adduser vxbus
- Automatically creates home directory
- Sets default shell and environment
Step 2: Generate SSH Key Pair (Local Machine) #
If you donโt already have a key pair:
PC$ ssh-keygen -t rsa -b 4096
- Keys stored in
~/.ssh/ - Optional: add a passphrase for extra protection
๐ก Modern alternative:
ed25519keys offer better performance and security.
Step 3: Copy Public Key to Server #
Use the recommended method:
PC$ ssh-copy-id -i ~/.ssh/id_rsa.pub vxbus@192.168.1.123
This ensures proper setup without manual errors.
๐ What Happens Behind the Scenes #
Running ssh-copy-id performs several critical actions:
- Creates
/home/vxbus/.ssh/if it doesnโt exist - Appends your public key to
authorized_keys - Sets strict permissions:
~/.ssh โ 700
authorized_keys โ 600
โ ๏ธ SSH will reject login if permissions are too open.
๐ก๏ธ Advanced Security Hardening #
Once key-based login works, disable password authentication:
Step 1: Edit SSH config #
sudo nano /etc/ssh/sshd_config
Step 2: Update setting #
PasswordAuthentication no
Step 3: Restart SSH service #
sudo systemctl restart ssh
This prevents attackers from even attempting password-based access.
โ Summary Checklist #
-
User Created Home directory and shell environment configured
-
Key Pair Generated
id_rsaandid_rsa.pubavailable -
Public Key Installed Present in
~/.ssh/authorized_keys -
Permissions Secured
.ssh= 700,authorized_keys= 600
๐ง Key Takeaway #
Passwordless SSH is not just a convenienceโitโs a security baseline for modern systems.
It enables:
- Safer remote access
- Automation (CI/CD, scripts, orchestration)
- Reduced attack surface
For larger environments, this setup becomes the foundation for tools like Ansible and other configuration management systems.