SSH permission denied after snapshot restore
user: I cant SSH into my server after restoring the snapshot. I see this in the terminal
adam@laptop:~$ ssh -p 47122 adam@ns0.mcwai.net
adam@ns0.mcwai.net: Permission denied (publickey).
adam@laptop:~$
assistant: Got it — that error means your server isn’t accepting your key anymore after the snapshot restore. Let’s go step by step:
---
### 1. Confirm what’s running
On your laptop, run:
```bash
ssh -vvv -p 47122 adam@ns0.mcwai.net
```
That will show verbose debug output. Look for:
- **Offering public key** — means your client is trying your keys.
- **Permission denied (publickey)** — means server rejected all offered keys.
---
### 2. Common causes after restoring a snapshot
- **Authorized keys lost**
`/home/adam/.ssh/authorized_keys` might not have your laptop’s public key anymore.
- **Wrong user home perms**
If `~/.ssh` perms are too open, OpenSSH refuses the key. They should be:
- `~/.ssh` → `700`
- `~/.ssh/authorized_keys` → `600`
- Home dir (`/home/adam`) → `755`
- **Different SSHD config**
Check `/etc/ssh/sshd_config`. Lines like:
```
PasswordAuthentication no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
```
If the snapshot reverted to stricter settings, it could block you.
- **Port mismatch**
Make sure SSH really listens on `47122`. From your laptop:
```bash
nc -zv ns0.mcwai.net 47122
```
---
### 3. Fix access
If you still have **console access (Hetzner panel, Proxmox, etc.)**, log in that way and check:
```bash
cat /home/adam/.ssh/authorized_keys
```
- If empty, paste your public key (`~/.ssh/id_rsa.pub` or `id_ed25519.pub`) into it.
- Then set permissions:
```bash
chmod 700 /home/adam/.ssh
chmod 600 /home/adam/.ssh/authorized_keys
chown -R adam:adam /home/adam/.ssh
```
Restart SSH just in case:
```bash
systemctl restart ssh
```
---
⚡ Question: Do you still have **console access to ns0** via your host (Hetzner rescue console, VNC, etc.)? That’s the easiest way to reinsert your key so SSH works again.
user: Just letting you know this ns0 server uses id_ed25519_ns0.pub and id_ed25519_ns0
Below is the status of what you tole me
adam@laptop:/etc/ssh$ cat ssh_config
# This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.
# Configuration data is parsed as follows:
# 1. command line options
# 2. user-specific file
# 3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.
# Site-wide defaults for some commonly used options. For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.
Include /etc/ssh/ssh_config.d/*.conf
Host *
# ForwardAgent no
# ForwardX11 no
# ForwardX11Trusted yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# GSSAPIKeyExchange no
# GSSAPITrustDNS no
# BatchMode no
# CheckHostIP no
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,umac-64@openssh.com
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
# RekeyLimit 1G 1h
# UserKnownHostsFile ~/.ssh/known_hosts.d/%k
SendEnv LANG LC_* COLORTERM NO_COLOR
HashKnownHosts yes
GSSAPIAuthentication yes
adam@laptop:/etc/ssh$
adam@laptop:~$ ssh -vvv -p 47122 adam@ns0.mcwai.net
debug1: OpenSSH_10.0p2 Debian-7, OpenSSL 3.5.1 1 Jul 2025
debug3: Running on Linux 6.12.41+deb13-a…
assistant: Thanks for sharing the debug trace — this makes things clearer.
The key part is here:
```
debug1: identity file /home/adam/.ssh/id_rsa type 0
...
debug1: identity file /home/adam/.ssh/id_ed25519 type 3
```
👉 Your SSH client is **not** trying `id_ed25519_ns0` at all — it’s only loading the defaults (`id_rsa`, `id_ed25519`, etc.). That’s why you’re getting:
```
Permission denied (publickey).
```
because the server only has your `id_ed25519_ns0.pub` installed in `~/.ssh/authorized_keys`.
---
### Fix on your laptop
You need to explicitly tell SSH to use `id_ed25519_ns0` when connecting to `ns0.mcwai.net`. Do this in your per-user SSH config (`~/.ssh/config`):
```sshconfig
Host ns0.mcwai.net
HostName ns0.mcwai.net
User adam
Port 47122
IdentityFile ~/.ssh/id_ed25519_ns0
IdentitiesOnly yes
```
Then test:
```bash
ssh ns0.mcwai.net
```
That will force SSH to use the correct private key.
---
### Quick one-time test without editing config
Run:
```bash
ssh -p 47122 -i ~/.ssh/id_ed25519_ns0 adam@ns0.mcwai.net
```
If that works, then add the block above to `~/.ssh/config` so you don’t need to keep typing it.
---
⚠️ Since you restored from a snapshot, there’s also a chance the `~/.ssh/authorized_keys` file on the **server** got reverted. If you still can’t log in after specifying the right key, you’ll need to re-inject your public key through the hosting provider’s console or rescue mode.
---
Do you want me to walk you through **checking/re-adding your public key on the server** in case the snapshot reverted it?
user: thanks, that that refreshed my memory, we already set this up. now I'm logged into the server
adam@laptop:~/.ssh$ cat config
# === NS0 (Ashburn) ===
Host ns0
HostName ns0.mcwai.net
Port 47122
User adam
IdentitiesOnly yes
IdentityFile ~/.ssh/id_ed25519_ns0
PubkeyAuthentication yes
# === NS1 (Helsinki) ===
Host ns1
HostName ns1.mcwai.net
Port 47122
User adam
IdentitiesOnly yes
IdentityFile ~/.ssh/ns1_ed25519
PubkeyAuthentication yes
# === NS2 (Ashburn secondary) ===
Host ns2
HostName ns2.mcwai.net
Port 47122
User adam
IdentitiesOnly yes
IdentityFile ~/.ssh/ns2_ed25519
PubkeyAuthentication yes
# === NS3 (Falkenstein) ===
Host ns3
HostName ns3.mcwai.net
Port 47122
User adam
IdentitiesOnly yes
IdentityFile ~/.ssh/id_ed25519_ns3
PubkeyAuthentication yes
Host galaxywatch
HostName galaxywatch
Port 8022
User u0_a167
IdentityFile ~/.ssh/id_rsa
Host ns2-vpn
HostName 10.8.0.2
User adam
Host 178.156.168.77
ServerAliveInterval 34
ServerAliveCountMax 5
Host 2a01:4ff:f0:b204::1
Port 47122
ServerAliveInterval 34
ServerAliveCountMax 5
Host ns2 ns2.mcwai.net
HostName ns2.mcwai.net
Port 47122
User adam
IdentityFile ~/.ssh/ns2_ed25519
IdentitiesOnly yes
adam@laptop:~/.ssh$
***************
Note: I don't want to type in the key passphrase every time I connect like this though. as seen below, you can see after I logout and log back in it ask again for the passphrase. do you have any advice?
***************
adam@laptop:~/.ssh$ ssh ns0
Enter passphrase for key '/home/adam/.ssh/id_ed25519_ns0':
Linux ns0 6.12.41+deb13-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.12.41-1 (2025-08-12) x86_64
Last login: Sun Sep 7 21:03:37 2025 from 2600:1006:b10e:78dd:d46c:c73a:192d:2984
adam@ns0:~$ exit
logout
Connection to ns0.mcwai.net closed.
adam@laptop:~/.ssh$ ssh ns0
Enter passphrase for key '/home/adam/.ssh/id_ed25519_ns0':
Linux ns0 6.12.41+deb13-cloud-…
assistant: Perfect — your config is solid, and the only reason it keeps asking is because your key has a **passphrase**. That’s good for security, but it means you need an **agent** to unlock it once per login session and keep it in memory.
Here are the best options:
---
### 1. Use `ssh-agent`
Start an agent and add your key:
```bash
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_ns0
```
It’ll prompt you once for the passphrase. After that, every `ssh ns0` works without asking until you log out.
If you want **all your keys** in, just run:
```bash
ssh-add -l # list loaded keys
ssh-add ~/.ssh/id_ed25519_* # add all your ed25519 keys
```
---
### 2. Auto-load with desktop keyring (KDE)
Since you’re on KDE now:
- KDE Wallet (or GNOME Keyring if installed) can remember your passphrase and auto-feed it to `ssh-agent`.
- On Plasma, check **System Settings → KDE Wallet** and ensure “Enable KDE wallet subsystem” is on.
- Then in `~/.bashrc` (or `~/.zshrc` if you use zsh), add:
```bash
eval "$(ssh-agent -s)" >/dev/null
ssh-add -q ~/.ssh/id_ed25519_ns0 </dev/null
```
This way, your wallet/agent asks only once per desktop login.
---
### 3. Security tradeoff
- **Keep passphrase + agent** → most secure, and only type it once per boot/session.
- **Remove passphrase** → you can strip the passphrase with:
```bash
ssh-keygen -p -f ~/.ssh/id_ed25519_ns0
```
(press Enter twice for new empty passphrase). But this makes the private key usable if anyone copies it off your machine.
---
✅ My recommendation for you:
Since you already have multiple keys (`ns0`, `ns1`, `ns2`, `ns3`), the clean way is to load them all into `ssh-agent` once per login. KDE Wallet can remember the passphrases if you don’t want to type them.
---
Do you want me to set you up with a **one-liner auto-agent setup** that adds all your `~/.ssh/id_ed25519_*` keys at login, so you never have to think about it again?
user: actually, i think that's what happened, I was using Gnome before and it was working as I wanted without asking for the password after the first time. does that make sense? do you still stick with your recommendation?
assistant: Yes, that makes perfect sense.
Gnome’s keyring (by default `gnome-keyring-daemon`) will unlock the first time you log in to your desktop session, and from then on it can silently provide your SSH private key’s passphrase to `ssh-agent`. That’s why it felt “automatic” after the first time — Gnome handled it for you.
Now that you’ve switched to KDE/Plasma, the default session doesn’t start `gnome-keyring-daemon`, so you’re being asked for the passphrase each time you use SSH. KDE can use its own wallet system (`KWallet`), but it doesn’t automatically integrate with SSH keys unless you configure it.
So my earlier recommendation (adding your key to `ssh-agent` with `ssh-add` and configuring it to load automatically) is the cross-desktop solution. It doesn’t matter if you’re on Gnome, KDE, or even just a TTY — it will work consistently.
That said, if you liked the “unlock once per login” style, you can:
- stick with my suggestion and configure your SSH key to auto-load into `ssh-agent` at session start, or
- configure KDE’s `KWallet` + `ssh-agent` integration (a bit more work, but possible).
👉 If you want, I can write you a short KDE/Plasma-specific setup so it behaves exactly like Gnome did — enter your key’s passphrase once per login, then it won’t ask again until you log out.
Do you want me to show you the KDE-native way, or do you prefer the universal `ssh-agent` + `ssh-add` setup?
user: actually, I want to strip the passphrase out. so what do I gotta do
assistant: Got it 👍 — if you don’t want to deal with `ssh-agent` or keyrings and just want a passphrase-free key, you can strip the passphrase from your private key.
Here’s how (run this on your **laptop**, not the server):
1. **Backup your existing private key first** (just in case something goes wrong):
```bash
cp ~/.ssh/id_rsa ~/.ssh/id_rsa.backup
```
(or if you’re using ed25519, adjust the filename accordingly, e.g. `id_ed25519`).
2. **Remove the passphrase**:
```bash
ssh-keygen -p -f ~/.ssh/id_rsa
```
It will ask:
```
Enter old passphrase:
Key has comment '...'
Enter new passphrase (empty for no passphrase):
```
→ Press **Enter** twice (for empty passphrase).
3. Now your private key has no passphrase. Test it:
```bash
ssh -p 47122 adam@ns0.mcwai.net
```
It should log you in without prompting.
---
⚠️ **Security note:** removing the passphrase means that if anyone gets a copy of your private key file, they can log into your server immediately. The passphrase is your “last line of defense.”
If you strip it, make sure your `~/.ssh/id_rsa` file is well protected:
```bash
chmod 600 ~/.ssh/id_rsa
```
Do you know whether your key is RSA (`id_rsa`) or Ed25519 (`id_ed25519`)? I can give you the exact command for your case.
user: its Ed25519
assistant: Perfect — that makes it even easier 🚀
On your **laptop**, do this:
1. **Backup your current private key** (always good practice):
```bash
cp ~/.ssh/id_ed25519 ~/.ssh/id_ed25519.backup
```
2. **Strip the passphrase** from the Ed25519 key:
```bash
ssh-keygen -p -f ~/.ssh/id_ed25519
```
It will prompt you:
```
Enter old passphrase:
Key has comment '...'
Enter new passphrase (empty for no passphrase):
```
→ Enter your current passphrase once, then just press **Enter** twice for the new passphrase (to leave it empty).
3. **Test login**:
```bash
ssh -p 47122 adam@ns0.mcwai.net
```
You should go straight in without being asked for the passphrase.
---
⚠️ Security reminder: now your Ed25519 private key has no protection. If someone copies `~/.ssh/id_ed25519`, they can log into your servers instantly. At minimum, make sure the file permissions are locked down:
```bash
chmod 600 ~/.ssh/id_ed25519
```
Want me to also show you how to generate a **fresh passphrase-free Ed25519 key** (instead of modifying your existing one), in case you’d rather keep the original passphrase-protected copy around for safer use?
Showing first 12 of 12 messages. View the full conversation at https://mcwai.org/ai-conversation/ssh-permission-denied-after-snapshot-restore