Using journalctl to hunt for rogue SSH key injections

Hunting for Rogue SSH Key Injections with journalctl

SSH key injection is a silent threat that can slip past static hardening. Attackers often add a malicious public key to a user’s authorized_keys file or to the system‑wide /etc/ssh/ssh_config.d/ directory, gaining persistence without leaving obvious footprints. The Linux journal, managed by systemd, records every authentication attempt, including the key fingerprint that was used. By querying journalctl for anomalous key fingerprints, you can spot unauthorized additions before they become a foothold.

[Read More]

Diagnosing a Persistent 0.0.0.0 Route That Blocks SSH via nftables

Persistent 0.0.0.0 Routes and SSH Blockage in nftables

When an SSH session drops halfway through, the first thing I usually check is the routing table. On a system that relies on nftables, a stale default route pointing to 0.0.0.0/0 that survived a network interface change can silently swallow the packets destined for the SSH server, making the client hang until it times out. Below is a hands‑on walk‑through of how I detect, diagnose, and fix this issue on a modern Linux host.

[Read More]

Fixing “Permission denied (publickey)” after moving /etc/ssh/sshd_config

“Permission denied (publickey)” after moving /etc/ssh/sshd_config

Moving the SSH daemon’s config file is one of those quick‑fixes that turns into a full‑blown headache. The first thing I see in production is the classic “Permission denied (publickey)” on every login attempt. In practice, it’s almost always a permissions or path mis‑match.

1. Verify the new location

# Example: moving to /opt/sshd/sshd_config
sudo mkdir -p /opt/sshd
sudo mv /etc/ssh/sshd_config /opt/sshd/

The daemon still expects /etc/ssh/sshd_config unless you tell it otherwise. I usually edit the systemd unit with a drop‑in:

[Read More]

Multi‑jump bastion access without storing keys: practical ssh‑agent forwarding

Multi‑jump Bastion Access Without Storing Keys

When you need to reach a private host behind a bastion, the first thing most people do is drop a private key on the jump machine and use it to hop over. That’s quick, but it gives the bastion a copy of the key it never should have. A cleaner pattern is to forward your local ssh‑agent through the bastion so the key never lands on the jump host.

[Read More]

Using SSH Agent Forwarding Safely

Avoiding key leaks when jumping through bastions

When you have to touch a host that lives behind several bastions, forwarding the agent is the quickest way to keep your private key off every hop. The catch? A compromised bastion can steal that key if you’re not careful. Below is a hands‑on walk‑through that shows how to tighten forwarding, what to watch out for, and how to double‑check that the key never ends up where it shouldn’t.

1. Understand the Threat Model

ThreatWhy it matters
Key exposureA breached bastion can use the forwarded key to reach downstream hosts.
MITMAn attacker could trick your local SSH client into forwarding the key to an arbitrary host.
Untrusted hostsSome internal services (monitoring agents, etc.) might run an SSH server that could request the key.

The aim is to confine the key to the exact hosts you trust and to stop accidental leaks.

[Read More]

Fixing SSH Jump Host Drops After OpenSSH 9.5

Diagnosing silent connection failures through a bastion

SSH jump host silently dropping connections after OpenSSH 9.5

A recent OpenSSH 9.5 release tweaked how the server handles TCP keepalive packets. My jump host – a modest Ubuntu 24.04 box – started dropping established SSH sessions after a few minutes of idle time. The problem popped up during a routine audit when several users complained of “connection closed” messages, yet nothing appeared in the logs.

What changed in 9.5?

OpenSSH 9.5 introduced new defaults for ClientAliveInterval and ClientAliveCountMax on the server side:

[Read More]

Fixing SSH Key Login Timeouts After Reboot

Troubleshooting ssh-config and ssh-agent behavior

When you power on a server and hit ssh user@host, the connection dies in a few seconds even though the key works on a fresh machine. The usual suspect is the SSH agent – it’s either not running or not forwarding the key after a reboot. The fix is straightforward: make the agent start automatically, add your key once, and let ssh_config do the rest.

1. Verify the agent is running

ssh-add -l

If you get The agent has no identities, the agent isn’t started or $SSH_AUTH_SOCK isn’t set. On most modern distros the agent is started by the display manager or a systemd‑user unit. Check it with:

[Read More]

Removing Stale SSH known_hosts Entries

Cleaning up after a host rebuild with ssh-keygen

When a host rebuilds, its SSH key changes

A fresh install or a system rebuild swaps the host’s RSA/ED25519 key pair.
If you still have the old key in ~/.ssh/known_hosts, the next SSH connection will trigger a “WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!” message.
That warning is a safety feature, but it also blocks automation and forces users to manually edit the file.

The quickest, safest way to clean up stale entries is to let OpenSSH do the work with ssh-keygen -R. The command removes every key that matches the supplied hostname or IP, regardless of whether the entry is hashed or plain.

[Read More]

Fixing SSH Password Prompts After Adding a Key

Correcting PubkeyAuthentication and key permissions

Why SSH Still Asks for a Password After Adding a Key

Adding a public key to ~/.ssh/authorized_keys is the first step toward password‑less login, but the SSH daemon can still fall back to password authentication for a handful of reasons. The most common culprit is a mis‑configured PubkeyAuthentication setting in /etc/ssh/sshd_config or a permissions problem that causes the server to ignore the key file.


1. Verify the Key Is Accepted by the Server

# On the client
ssh -vvv user@host

The -vvv flag prints the entire authentication dance. Look for lines like:

[Read More]

Extracting SSH Login Failures with grep and awk

Building a CSV from /var/log/auth.log

A quick way to see who’s repeatedly failing to log in via SSH is to pull the relevant lines from /var/log/auth.log and turn them into a CSV. The CSV can then be fed into a spreadsheet, a Grafana dashboard, or a simple shell script that alerts you when a user crosses a threshold. Below is a step‑by‑step recipe that uses only grep and awk, two tools that are guaranteed to be present on any modern Linux distribution.

[Read More]