Nmap Ssh-hostkey Script

Published
Length
3 min read

Luis Felipe Dias

All posts

The nmap ssh hostkey script fetches public keys and fingerprints from remote SSH servers. Teams run it to check server identity before users log in. Admins often scan their networks to track host keys across many machines. Still, checking a server key only confirms the machine identity at login. Broad user roles on that machine still allow risky actions after login. How the nmap ssh hostkey script works Every SSH server holds public and private host keys to prove its identity. When you run th

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

The nmap ssh hostkey script fetches public keys and fingerprints from remote SSH servers. Teams run it to check server identity before users log in. Admins often scan their networks to track host keys across many machines. Still, checking a server key only confirms the machine identity at login. Broad user roles on that machine still allow risky actions after login.

How the nmap ssh hostkey script works

Every SSH server holds public and private host keys to prove its identity. When you run the nmap ssh hostkey script, the scanner starts a handshake. It asks the remote service to send its public keys for each key type. The script reads these public keys and shows their short fingerprint hashes. It can also show the full public key string when you need more detail.

Security teams use these scans to spot duplicate host keys across a network. Cloned virtual machines often share the exact same host keys by mistake. If an attacker steals one shared key, they can spoof any cloned server. Regular network scans help teams find and replace these matching keys fast.

Teams can also pair host checks with OpenSSH host certificates. An OpenSSH certificate holds a public key, identity data, and principal names. A Certification Authority key signs these details in a simple format. When a server uses a signed host certificate, clients trust the signing key. They do not need to check single host fingerprints on every new server.

What host key checks solve and what they leave open

Host key checks stop attackers from faking a server on the network. They also help teams keep a clean list of active SSH hosts. If a rogue server appears with an unknown key, the scan flags it. This protects users from sending login secrets to a fake machine.

Yet host key checks only handle the first step of a login. They tell the client that the server is real. They do not control what an engineer does after the shell opens. Once a user logs in with broad permissions, host keys offer zero control.

SSH Access Management: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

A user with root rights can still run bad commands or read sensitive files. Standard server logs often miss the full text of every shell command. Teams know which server the user reached, but not what changed inside. They also cannot mask private data like emails or card numbers in flight.

Managing host keys at scale

Large teams often move away from manual fingerprint checks on every single machine. Instead, they sign host keys with a central key to build trust. The signing tool adds an identity name and a list of valid hostnames. Admins also set a time window so the signed certificate expires on schedule. Without a time window, an OpenSSH certificate stays valid forever by default.

Even with signed host keys, teams must still watch active user sessions. Checking the server identity is only half of the security puzzle. You also need fine control over the commands that run inside each session. Combining host checks with command controls closes the gap between login and execution.

Add command and file guardrails to SSH access

Host firewalls and certificate principals control who opens an SSH session. Yet an allowed user or agent can still run a bad one-shot command or pull sensitive files over sftp. In practice, hoop.dev provides an open-source SSH server with guardrails on the host that uses OpenSSH certificates.

Using hoop.dev SSH controls, guardrails check one-shot commands, env variable names, and sftp or scp paths before they run. Port forwards default to deny unless the target is listed. Because interactive shells have no statement boundary and carry no guardrails, teams can turn them off so every command is checked and logged. Check out the MIT-licensed project on GitHub.

Frequently asked questions

What does the nmap ssh hostkey script return during a scan?

The script returns the public key fingerprints for each algorithm the SSH server supports. It can also output the full public key data if you request extra detail.

Why do duplicate SSH host keys happen on a network?

Duplicate keys usually happen when teams clone virtual machine images that already have keys. Every cloned server then boots up with the exact same host identity.

Does checking an SSH host key restrict what users can run?

No, a host key only proves the identity of the remote server during login. It does not restrict shell commands or protect data after the session starts.

The query runs. The emails stay hidden.