Easily Remove Stale Entries from ~/.ssh/known_hosts When a Host Rebuilds with ssh-keygen ‑R

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]

Why ssh keeps asking for a password after adding a key and how to correct the PubkeyAuthentication setting

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]

Using grep and awk to pull per‑user SSH login failures from /var/log/auth.log into a CSV file

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]

Using rsync and SSH to Automate Offsite Backups of Important Configuration Files

Introduction to Automated Offsite Backups

I’ve seen this go wrong when people don’t prioritize backups - losing important configuration files can be a real headache. Automating offsite backups is a crucial task for any Linux user, whether you’re a sysadmin, self-hoster, or homelab enthusiast. By leveraging rsync and SSH, you can create a reliable and secure backup system. In this article, we’ll explore how to set up automated offsite backups using these tools.

[Read More]

Using SSH Keys with Multiple Accounts on a Single Remote Server

Introduction to SSH Keys with Multiple Accounts

I’ve seen this go wrong when people try to manage multiple services or projects on a single remote server - they end up with a mess of passwords and login issues. Using SSH keys with multiple accounts is a much better approach. It allows for secure, passwordless login to different user accounts on the same server, which is particularly useful for sysadmins, developers, and self-hosters.

[Read More]

Troubleshooting SSH Connection Issues with Unknown Hosts and Missing Host Keys

Introduction to SSH Connection Issues

I’ve seen my fair share of SSH connection issues over the years, especially when dealing with new servers or changes in network configurations. Secure Shell (SSH) is a fundamental tool for remote access and management in Linux, but issues with unknown hosts and missing host keys can be a real headache. Understanding how to troubleshoot and resolve these issues is crucial for efficient system administration and security.

[Read More]

Taming SSH Config Chaos: Organizing Your SSH Client Settings for Multiple Servers and Identities

Taming SSH Config Chaos

If you’re like me, you’re constantly juggling multiple servers and identities. Managing SSH connections can be a real headache, especially when dealing with different usernames, ports, and private keys. See managing multiple SSH identities and agents for a deeper dive. I’ve seen this go wrong when you have to remember a dozen different connection settings. The real trick is to organize your SSH client settings in a way that makes sense for your workflow.

[Read More]

Using SSH to Tunnel Traffic Through a Jump Host for Secure Access to a Remote Network

Introduction to SSH Tunneling

I’ve seen this go wrong when people try to access remote networks without using a secure method - that’s where SSH tunneling comes in. This technique leverages an intermediate host, known as a jump host, to securely access remote networks. If you also need to transfer files, see transferring files over a jump host with SSH and rsync. It’s particularly useful when direct access is restricted due to firewall rules or network policies. By using SSH to tunnel traffic through a jump host, you can establish a secure connection to a remote server or network, even if direct access is not possible.

[Read More]

Using SSH Keys with Multiple Identities and Agents for Simplified Remote Access

Introduction to SSH Keys and Agents

I’ve seen many Linux users struggle with managing multiple remote systems, but SSH keys and agents can make a huge difference. By using SSH keys, you can authenticate to remote servers without entering a password, making it easier to manage multiple systems. In practice, this means you can quickly switch between systems without having to remember a bunch of passwords.

Generating SSH Keys

To start using SSH keys, you need to generate a key pair on your local system. I usually start with the ssh-keygen command to generate a key pair:

[Read More]

Mastering SSH Connection Sharing with ControlMaster and ControlPersist

Introduction to SSH Connection Sharing

I’ve seen this go wrong when people don’t understand how SSH connection sharing works. It’s actually pretty simple: SSH connection sharing is a feature that allows you to reuse an existing SSH connection for multiple SSH sessions. This can significantly speed up your workflow, especially when working with remote servers. In this article, we’ll explore how to master SSH connection sharing using ControlMaster and ControlPersist.

[Read More]