SSH-KEYSCAN(1)
๐ป SSH-KEYSCAN(1) โ the gather-SSH-keys baddie
okay so bestie, welcome to the ssh-keyscan(1) page from the General Commands Manual โ yes it's a real section, yes it's iconic, and yes we're gonna read it together. grab a snack ๐
โจ NAME โจ
ssh-keyscan โ literally just gather SSH public keys from servers. that's it. that's the whole job. ๐
๐ฆ SYNOPSIS ๐ฆ
ssh-keyscan [-46cDHqv] [-f file] [-O option] [-p port] [-T timeout]
[-t type] [host | addrlist namelist]
๐ธ DESCRIPTION ๐ธ
okay so ssh-keyscan is a utility for gathering the public SSH host keys of a number of hosts. it was designed to aid in building and verifying ssh_known_hosts files โ the format of that is documented over in sshd(8), go look, iykyk. and it provides a minimal interface that's suitable for use by shell and perl scripts. script girlies, this one's for you ๐ซถ
ssh-keyscan uses non-blocking socket I/O to contact as many hosts as possible in parallel, so it is very efficient. the keys from a domain of 1,000 hosts can be collected in tens of seconds โ even when some of those hosts are down or do not run sshd(8). not me being fast AND reliable ๐ญโจ
for scanning, one does not need login access to the machines that are being scanned, nor does the scanning process involve any encryption. no login, no crypto, no stress, no cap ๐
hosts to be scanned may be specified by hostname, address, or by CIDR network range (e.g. 192.168.16/28). if a network range is specified, then all addresses in that range will be scanned. every single one. main character sweep ๐
the options are as follows:
๐ OPTIONS ๐
-4โ forcessh-keyscanto use IPv4 addresses only.-6โ forcessh-keyscanto use IPv6 addresses only.-cโ request certificates from target hosts instead of plain keys. fancy โจ-Dโ print keys found as SSHFP DNS records. the default is to print keys in a format usable as anssh(1)known_hostsfile.-ffileโ read hosts or "addrlist namelist" pairs fromfile, one per line. details below because there's lore ๐-Hโ hash all hostnames and addresses in the output. hashed names may be used normally byssh(1)andsshd(8), but they do not reveal identifying information should the file's contents be disclosed. privacy queen ๐-Ooptionโ specify a key/value option. at present, only a single option is supported:hashalg=algorithmโ selects a hash algorithm to use when printing SSHFP records using the-Dflag. valid algorithms are "sha1" and "sha256". the default is to print both.
-pportโ connect toporton the remote host.-qโ quiet mode: do not print server host name and banners in comments. shhh ๐คซ-Ttimeoutโ set the timeout for connection attempts. iftimeoutseconds have elapsed since a connection was initiated to a host or since the last time anything was read from that host, the connection is closed and the host in question considered unavailable. the default is 5 seconds.-ttypeโ specify the type of the key to fetch from the scanned hosts. the possible values are "ecdsa", "ed25519", "ecdsa-sk", "ed25519-sk", or "rsa". multiple values may be specified by separating them with commas. the default is to fetch all the above key types.-vโ verbose mode: print debugging messages about progress. talk to me bestie ๐ฃ๏ธ
๐ง -f file โ the deep dive ๐ง
read hosts or "addrlist namelist" pairs from file, one per line. if '-' is supplied instead of a filename, ssh-keyscan will read from the standard input. stdin stans rise ๐
names read from a file must start with an address, hostname or CIDR network range to be scanned. addresses and hostnames may optionally be followed by comma-separated name or address aliases that will be copied to the output. for example:
192.168.11.0/24
10.20.1.1
happy.example.org
10.0.0.1,sad.example.org
like, the file format really said "here's my range, here's my host, here's happy.example.org living her best life, and here's 10.0.0.1 with her alias sad.example.org" ๐ญ iconic lineup
โ ๏ธ okay this part is IMPORTANT, listen up. if anssh_known_hostsfile is constructed usingssh-keyscanwithout verifying the keys, users will be vulnerable to man in the middle attacks. like, genuinely. not a vibe. ๐ on the other hand, if the security model allows such a risk,ssh-keyscancan help in the detection of tampered keyfiles or man in the middle attacks which have begun after thessh_known_hostsfile was created. so it's giving "useful but read the warning" energy.
๐๏ธ FILES ๐๏ธ
/etc/ssh/ssh_known_hosts
๐ EXAMPLES ๐
print the RSA host key for machine hostname:
$ ssh-keyscan -t rsa hostname
search a network range, printing all supported key types:
$ ssh-keyscan 192.168.0.64/25
find all hosts from the file ssh_hosts which have new or different keys from those in the sorted file ssh_known_hosts:
$ ssh-keyscan -t rsa,ecdsa,ed25519 -f ssh_hosts | \
sort -u - ssh_known_hosts | diff ssh_known_hosts -
not the pipe and the diff and the trailing -... she ate ๐ฅ
๐ SEE ALSO ๐
๐ AUTHORS ๐
David Mazieres <dm@lcs.mit.edu> wrote the initial version, and Wayne Davison <wayned@users.sourceforge.net> added support for protocol version 2. legends, both of them ๐ซถ
and that's the whole page, bestie โ no notes, periodt. ๐
this lil rewrite is brought to you by the Debian edition, dated October 4, 2025, and it's still filed under SSH-KEYSCAN(1) in the General Commands Manual. ๐
๐ฆ where this page comes from
- alpine 3.23: openssh-doc 10.2_p1-r0 ยท SSH-OpenSSH
- alpine 3.24: openssh-doc 10.3_p1-r1 ยท SSH-OpenSSH
- fedora 44: openssh-clients 10.2p1-14.fc44
- fedora 44: openssh-clients 10.2p1-16.fc44 ยท BSD-3-Clause AND BSD-2-Clause AND ISC AND SSH-OpenSSH AND ssh-keyscan AND snprintf AND LicenseRef-Fedora-Public-Domain AND X11-distribute-modifications-variant
- fedora 44: openssh-clients 10.2p1-7.fc44 ยท BSD-3-Clause AND BSD-2-Clause AND ISC AND SSH-OpenSSH AND ssh-keyscan AND snprintf AND LicenseRef-Fedora-Public-Domain AND X11-distribute-modifications-variant
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3 ยท OpenSSH
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3.6
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3.7
- ubuntu resolute: openssh-client 1:10.2p1-2ubuntu3.8 ยท OpenSSH
- Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms