xref: /freebsd/crypto/openssh/ssh-keyscan.1 (revision a259b98fa211ed87bfee58c575de4e2de94ee0fa)
1.\"	$OpenBSD: ssh-keyscan.1,v 1.54 2026/06/26 06:17:13 djm Exp $
2.\"
3.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
4.\"
5.\" Modification and redistribution in source and binary forms is
6.\" permitted provided that due credit is given to the author and the
7.\" OpenBSD project by leaving this copyright notice intact.
8.\"
9.Dd $Mdocdate: June 26 2026 $
10.Dt SSH-KEYSCAN 1
11.Os
12.Sh NAME
13.Nm ssh-keyscan
14.Nd gather SSH public keys from servers
15.Sh SYNOPSIS
16.Nm ssh-keyscan
17.Op Fl 46cDHqv
18.Op Fl f Ar file
19.Op Fl O Ar option
20.Op Fl p Ar port
21.Op Fl T Ar timeout
22.Op Fl t Ar type
23.Op Ar host | addrlist namelist
24.Sh DESCRIPTION
25.Nm
26is a utility for gathering the public SSH host keys of a number of
27hosts.
28It was designed to aid in building and verifying
29.Pa ssh_known_hosts
30files,
31the format of which is documented in
32.Xr sshd 8 .
33.Nm
34provides a minimal interface suitable for use by shell and perl
35scripts.
36.Pp
37.Nm
38uses non-blocking socket I/O to contact as many hosts as possible in
39parallel, so it is very efficient.
40The keys from a domain of 1,000
41hosts can be collected in tens of seconds, even when some of those
42hosts are down or do not run
43.Xr sshd 8 .
44For scanning, one does not need
45login access to the machines that are being scanned, nor does the
46scanning process involve any encryption.
47.Pp
48Hosts to be scanned may be specified by hostname, address or by CIDR
49network range (e.g. 192.168.16/28).
50If a network range is specified, then all addresses in that range will
51be scanned.
52.Pp
53.Nm
54cannot verify the authenticity of the host keys it obtains, and an attacker
55on the network with the ability to intercept traffic could substitute their
56own host keys to enable impersonation of servers.
57Because of this,
58.Nm
59output should be verified out of band, or only used directly for host
60authentication if the network is trusted.
61.Pp
62The options are as follows:
63.Bl -tag -width Ds
64.It Fl 4
65Force
66.Nm
67to use IPv4 addresses only.
68.It Fl 6
69Force
70.Nm
71to use IPv6 addresses only.
72.It Fl c
73Request certificates from target hosts instead of plain keys.
74.It Fl D
75Print keys found as SSHFP DNS records.
76The default is to print keys in a format usable as an
77.Xr ssh 1
78.Pa known_hosts
79file.
80.It Fl f Ar file
81Read hosts or
82.Dq addrlist namelist
83pairs from
84.Ar file ,
85one per line.
86If
87.Sq -
88is supplied instead of a filename,
89.Nm
90will read from the standard input.
91Names read from a file must start with an address, hostname or CIDR network
92range to be scanned.
93Addresses and hostnames may optionally be followed by comma-separated name
94or address aliases that will be copied to the output.
95For example:
96.Bd -literal
97192.168.11.0/24
9810.20.1.1
99happy.example.org
10010.0.0.1,sad.example.org
101.Ed
102.It Fl H
103Hash all hostnames and addresses in the output.
104Hashed names may be used normally by
105.Xr ssh 1
106and
107.Xr sshd 8 ,
108but they do not reveal identifying information should the file's contents
109be disclosed.
110.It Fl O Ar option
111Specify a key/value option.
112At present, only a single option is supported:
113.Bl -tag -width Ds
114.It Cm hashalg Ns = Ns Ar algorithm
115Selects a hash algorithm to use when printing SSHFP records using the
116.Fl D
117flag.
118Valid algorithms are
119.Dq sha1
120and
121.Dq sha256 .
122The default is to print both.
123.El
124.It Fl p Ar port
125Connect to
126.Ar port
127on the remote host.
128.It Fl q
129Quiet mode:
130do not print server host name and banners in comments.
131.It Fl T Ar timeout
132Set the timeout for connection attempts.
133If
134.Ar timeout
135seconds have elapsed since a connection was initiated to a host or since the
136last time anything was read from that host, the connection is
137closed and the host in question considered unavailable.
138The default is 5 seconds.
139.It Fl t Ar type
140Specify the type of the key to fetch from the scanned hosts.
141The possible values are
142.Dq ecdsa ,
143.Dq ed25519 ,
144.Dq ecdsa-sk ,
145.Dq ed25519-sk ,
146or
147.Dq rsa .
148Multiple values may be specified by separating them with commas.
149The default is to fetch all the above key types.
150.It Fl v
151Verbose mode:
152print debugging messages about progress.
153.El
154.Pp
155If an ssh_known_hosts file is constructed using
156.Nm
157without verifying the keys, users will be vulnerable to
158.Em man in the middle
159attacks.
160On the other hand, if the security model allows such a risk,
161.Nm
162can help in the detection of tampered keyfiles or man in the middle
163attacks which have begun after the ssh_known_hosts file was created.
164.Sh FILES
165.Pa /etc/ssh/ssh_known_hosts
166.Sh EXAMPLES
167Print the RSA host key for machine
168.Ar hostname :
169.Pp
170.Dl $ ssh-keyscan -t rsa hostname
171.Pp
172Search a network range, printing all supported key types:
173.Pp
174.Dl $ ssh-keyscan 192.168.0.64/25
175.Pp
176Find all hosts from the file
177.Pa ssh_hosts
178which have new or different keys from those in the sorted file
179.Pa ssh_known_hosts :
180.Bd -literal -offset indent
181$ ssh-keyscan -t rsa,ecdsa,ed25519 -f ssh_hosts | \e
182	sort -u - ssh_known_hosts | diff ssh_known_hosts -
183.Ed
184.Sh SEE ALSO
185.Xr ssh 1 ,
186.Xr sshd 8
187.Rs
188.%D 2006
189.%R RFC 4255
190.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
191.Re
192.Sh AUTHORS
193.An -nosplit
194.An David Mazieres Aq Mt dm@lcs.mit.edu
195wrote the initial version, and
196.An Wayne Davison Aq Mt wayned@users.sourceforge.net
197added support for protocol version 2.
198