The first way most people reach a homelab server is SSH, the secure remote login that lets you control your mini PC from another computer. By default it accepts a username and password. That works, but passwords can be guessed, reused, or stolen. SSH keys are a stronger replacement: your computer proves who it is with a cryptographic key, and the server can then stop accepting passwords at all.
This guide shows how to create an SSH key, install it on your Ubuntu Server mini PC, and turn off password login without locking yourself out. The commands are standard OpenSSH tools, but I have not run every step on a fresh install for this article, so follow the safety checks in each section and keep a second way into the server until the end.
Why keys are safer than passwords
An SSH key is a pair of files. The private key stays on your own computer and is never shared. The public key goes on the server. When you connect, the two prove they match without any password crossing the network. An attacker who guesses passwords all day gets nowhere, because there is no password to guess.
On a home network this matters less if the server is never reachable from the internet. But it is still good practice, it takes about ten minutes, and it protects you if you later expose the server or a device on your network is compromised.
Before you start
- Ubuntu Server running with the OpenSSH server installed. If you are still setting up, follow our Ubuntu Server install guide.
- Your server’s IP address and a username with
sudorights. - A terminal on your own computer. Linux and macOS have one built in. Recent versions of Windows include the OpenSSH client in PowerShell.
- A second way in, such as a keyboard and monitor on the mini PC, so a mistake cannot lock you out for good.
If you are new to the terminal, our Linux commands for homelab beginners guide explains the commands used below.
Step 1: Create a key pair on your computer
Run this on your own computer, not on the server:
ssh-keygen -t ed25519 -C "homelab"
Press Enter to accept the default location. When asked for a passphrase, set one. A passphrase protects the private key if someone ever copies the file. You can store the passphrase in a password manager such as a self-hosted Vaultwarden or a hosted one.
This creates two files in your .ssh folder: id_ed25519 (private, keep it secret) and id_ed25519.pub (public, safe to share). Only the .pub file ever goes on the server.
Step 2: Copy the public key to the server
On Linux or macOS, use ssh-copy-id. Replace the username and IP with yours:
ssh-copy-id -i ~/.ssh/id_ed25519.pub youruser@192.168.1.50
You will be asked for your password one last time. The command adds your key to ~/.ssh/authorized_keys on the server and sets the right permissions.
On Windows, ssh-copy-id may not exist. Log in with your password, then append the key by hand. Show the key on your computer, copy the single line, and on the server run:
mkdir -p ~/.ssh
chmod 700 ~/.ssh
nano ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
Paste the public key as one line in the file, then save.
Step 3: Test the key before changing anything
Open a new terminal window and connect:
ssh youruser@192.168.1.50
If the key works, you are asked for your key passphrase (if you set one) instead of the server password, and you land at the server’s prompt. If it still asks for the server password, stop here and fix the key first. Do not continue until this works.
Step 4: Turn off password login
Ubuntu reads extra settings from small files in /etc/ssh/sshd_config.d/, and these can override the main file. Ubuntu’s own documentation notes that its default configuration includes Include /etc/ssh/sshd_config.d/*.conf at the very top of sshd_config. This is the usual reason people set PasswordAuthentication no in the main file and find passwords still work.
First, look at what is already there:
ls -la /etc/ssh/sshd_config.d/
sudo grep -ri PasswordAuthentication /etc/ssh/sshd_config /etc/ssh/sshd_config.d/
Some installs, especially ones set up with cloud-init, include a file such as 50-cloud-init.conf that sets PasswordAuthentication yes. Because SSH uses the first value it finds, give your own file a name that sorts first:
sudo nano /etc/ssh/sshd_config.d/01-hardening.conf
PasswordAuthentication no
PermitRootLogin no
Check the settings for mistakes, then apply them:
sudo sshd -t
sudo systemctl restart ssh
On Ubuntu 24.04, SSH is started through a socket service. Restarting ssh applies authentication changes. If you also change the SSH port, guides recommend running sudo systemctl daemon-reload and sudo systemctl restart ssh.socket. Changing the port only reduces log noise and is not real protection, so it is optional.
Step 5: Confirm it worked, and keep your old session open
Keep your current terminal connected. In another window, check what the server is actually using:
sudo sshd -T | grep -i passwordauthentication
It should print passwordauthentication no. Then open a new connection. Your key should work. To prove passwords are refused, try:
ssh -o PubkeyAuthentication=no youruser@192.168.1.50
You should get “Permission denied (publickey)”. If your key login fails, use the still-open session or the keyboard on the mini PC to delete 01-hardening.conf and restart ssh.
Extra steps worth taking
- Use a firewall. Allow only the ports you need with
ufw, and make sure SSH is allowed before you enable it. - Do not expose SSH to the internet. Avoid forwarding port 22 on your router. For remote access, use Tailscale, and read home network basics to understand what a router port forward actually exposes.
- Back up your private key somewhere safe and offline. If you lose it and have turned off passwords, you will need physical access to recover.
- Keep the server updated so security fixes for OpenSSH are installed.
Troubleshooting
| Symptom | Likely cause and fix |
|---|---|
| Still asks for the server password | The key was not installed, or file permissions are wrong. Check ~/.ssh is 700 and authorized_keys is 600 on the server. |
Passwords still work after setting PasswordAuthentication no | Another file in sshd_config.d overrides it. Run the grep command above and fix or rename the file. |
| Permission denied (publickey) | The server has no matching public key for the user you are logging in as. Re-run ssh-copy-id with the right user. |
| Connection refused | The SSH service is not running or a firewall blocks it. Check sudo systemctl status ssh. |
| Changes do not take effect | Run sudo sshd -t for errors, then restart the service again. |
Frequently asked questions
Do I still need a strong password for sudo?
Yes. Turning off SSH passwords only changes how you log in remotely. Your account password is still used for sudo on the server, so keep it strong.
Which key type should I use?
Ed25519 is a good modern default and is what current guides recommend. If you need compatibility with very old systems, a long RSA key (4096 bits) also works.
Can I use one key on several computers?
It is better to create a separate key on each computer and add every public key to authorized_keys. If one computer is lost, you remove only that key.
What if I lock myself out?
Connect a keyboard and monitor to the mini PC, log in locally, remove the file you created in sshd_config.d, and restart ssh. This is why keeping a second way in matters.