ssh-keyscan
Collect server host keys for later inspection.
Before you run
Collected keys are NOT authenticated. Compare fingerprints with a trusted administrator or independent trusted source before adding anything to known_hosts. Never pipe unverified output straight into known_hosts. Scanning is not login and does not prove access. The redirection below overwrites hostkeys.txt if it exists.
Examples
Collect port 2222 host keys into a local file with a five-second timeout.
ssh-keyscan -T 5 -p 2222 server.example.com > hostkeys.txtPrint collected fingerprints; verify them independently before trusting.
ssh-keygen -lf hostkeys.txtOptions and examples
-p portCommonQuery the specified SSH port.
Example
ssh-keyscan -p 2222 server.example.com-T timeoutCommonSet the connection timeout in seconds.
Example
ssh-keyscan -T 5 server.example.com-t typeCommonRequest specific host-key types, separated by commas.
Example
ssh-keyscan -t ed25519,rsa server.example.com-4 / -6Use IPv4 only or IPv6 only, respectively.
Example
ssh-keyscan -4 server.example.com-f fileRead host names or addresses from a file, one per line.
Example
ssh-keyscan -f hosts.txt-HHash host names in output. This does not authenticate the returned keys.
Example
ssh-keyscan -H server.example.com-cRequest host certificates instead of plain host keys when supported.
Example
ssh-keyscan -c server.example.comAuthoritative references
Reviewed October 27, 2026