1SSH-KEYSCAN(1) BSD General Commands Manual SSH-KEYSCAN(1)
2
4 ssh-keyscan — gather SSH public keys from servers
5
7 ssh-keyscan [-46cDHv] [-f file] [-O option] [-p port] [-T timeout]
8 [-t type] [host | addrlist namelist]
9
11 ssh-keyscan is a utility for gathering the public SSH host keys of a num‐
12 ber of hosts. It was designed to aid in building and verifying
13 ssh_known_hosts files, the format of which is documented in sshd(8).
14 ssh-keyscan provides a minimal interface suitable for use by shell and
15 perl scripts.
16
17 ssh-keyscan uses non-blocking socket I/O to contact as many hosts as pos‐
18 sible in parallel, so it is very efficient. The keys from a domain of
19 1,000 hosts can be collected in tens of seconds, even when some of those
20 hosts are down or do not run sshd(8). For scanning, one does not need
21 login access to the machines that are being scanned, nor does the scan‐
22 ning process involve any encryption.
23
24 Hosts to be scanned may be specified by hostname, address or by CIDR net‐
25 work range (e.g. 192.168.16/28). If a network range is specified, then
26 all addresses in that range will be scanned.
27
28 The options are as follows:
29
30 -4 Force ssh-keyscan to use IPv4 addresses only.
31
32 -6 Force ssh-keyscan to use IPv6 addresses only.
33
34 -c Request certificates from target hosts instead of plain keys.
35
36 -D Print keys found as SSHFP DNS records. The default is to print
37 keys in a format usable as a ssh(1) known_hosts file.
38
39 -f file
40 Read hosts or “addrlist namelist” pairs from file, one per line.
41 If ‘-’ is supplied instead of a filename, ssh-keyscan will read
42 from the standard input. Names read from a file must start with
43 an address, hostname or CIDR network range to be scanned. Ad‐
44 dresses and hostnames may optionally be followed by comma-sepa‐
45 rated name or address aliases that will be copied to the output.
46 For example:
47
48 192.168.11.0/24
49 10.20.1.1
50 happy.example.org
51 10.0.0.1,sad.example.org
52
53 -H Hash all hostnames and addresses in the output. Hashed names may
54 be used normally by ssh(1) and sshd(8), but they do not reveal
55 identifying information should the file's contents be disclosed.
56
57 -O option
58 Specify a key/value option. At present, only a single option is
59 supported:
60
61 hashalg=algorithm
62 Selects a hash algorithm to use when printing SSHFP
63 records using the -D flag. Valid algorithms are “sha1”
64 and “sha256”. The default is to print both.
65
66 -p port
67 Connect to port on the remote host.
68
69 -T timeout
70 Set the timeout for connection attempts. If timeout seconds have
71 elapsed since a connection was initiated to a host or since the
72 last time anything was read from that host, the connection is
73 closed and the host in question considered unavailable. The de‐
74 fault is 5 seconds.
75
76 -t type
77 Specify the type of the key to fetch from the scanned hosts. The
78 possible values are “dsa”, “ecdsa”, “ed25519”, “ecdsa-sk”,
79 “ed25519-sk”, or “rsa”. Multiple values may be specified by sep‐
80 arating them with commas. The default is to fetch “rsa”,
81 “ecdsa”, “ed25519”, “ecdsa-sk”, and “ed25519-sk” keys.
82
83 -v Verbose mode: print debugging messages about progress.
84
85 If an ssh_known_hosts file is constructed using ssh-keyscan without veri‐
86 fying the keys, users will be vulnerable to man in the middle attacks.
87 On the other hand, if the security model allows such a risk, ssh-keyscan
88 can help in the detection of tampered keyfiles or man in the middle at‐
89 tacks which have begun after the ssh_known_hosts file was created.
90
92 /etc/ssh/ssh_known_hosts
93
95 Print the RSA host key for machine hostname:
96
97 $ ssh-keyscan -t rsa hostname
98
99 Search a network range, printing all supported key types:
100
101 $ ssh-keyscan 192.168.0.64/25
102
103 Find all hosts from the file ssh_hosts which have new or different keys
104 from those in the sorted file ssh_known_hosts:
105
106 $ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \
107 sort -u - ssh_known_hosts | diff ssh_known_hosts -
108
110 ssh(1), sshd(8)
111
112 Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints, RFC
113 4255, 2006.
114
116 David Mazieres <dm@lcs.mit.edu> wrote the initial version, and Wayne
117 Davison <wayned@users.sourceforge.net> added support for protocol version
118 2.
119
120BSD February 10, 2023 BSD