xref: /netbsd-src/crypto/external/bsd/openssh/dist/ssh-keyscan.1 (revision 1c7715dda22cf2bd169e2f84953c050393e8fe9c)
1*1c7715ddSchristos.\"	$NetBSD: ssh-keyscan.1,v 1.19 2024/07/08 22:33:44 christos Exp $
2*1c7715ddSchristos.\"	$OpenBSD: ssh-keyscan.1,v 1.52 2024/06/17 08:30:29 djm Exp $
3ca32bd8dSchristos.\"
4ca32bd8dSchristos.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
5ca32bd8dSchristos.\"
6ca32bd8dSchristos.\" Modification and redistribution in source and binary forms is
7ca32bd8dSchristos.\" permitted provided that due credit is given to the author and the
8ca32bd8dSchristos.\" OpenBSD project by leaving this copyright notice intact.
9ca32bd8dSchristos.\"
10*1c7715ddSchristos.Dd June 17 2024
11ca32bd8dSchristos.Dt SSH-KEYSCAN 1
12ca32bd8dSchristos.Os
13ca32bd8dSchristos.Sh NAME
14ca32bd8dSchristos.Nm ssh-keyscan
15ed75d7a8Schristos.Nd gather SSH public keys from servers
16ca32bd8dSchristos.Sh SYNOPSIS
17ca32bd8dSchristos.Nm ssh-keyscan
18*1c7715ddSchristos.Op Fl 46cDHqv
19ca32bd8dSchristos.Op Fl f Ar file
20b1066cf3Schristos.Op Fl O Ar option
21ca32bd8dSchristos.Op Fl p Ar port
22ca32bd8dSchristos.Op Fl T Ar timeout
23ca32bd8dSchristos.Op Fl t Ar type
24ca32bd8dSchristos.Op Ar host | addrlist namelist
25ca32bd8dSchristos.Sh DESCRIPTION
26ca32bd8dSchristos.Nm
27ffae97bbSchristosis a utility for gathering the public SSH host keys of a number of
28ca32bd8dSchristoshosts.
29ca32bd8dSchristosIt was designed to aid in building and verifying
30ca32bd8dSchristos.Pa ssh_known_hosts
31ffae97bbSchristosfiles,
32ffae97bbSchristosthe format of which is documented in
33ffae97bbSchristos.Xr sshd 8 .
34ca32bd8dSchristos.Nm
35ca32bd8dSchristosprovides a minimal interface suitable for use by shell and perl
36ca32bd8dSchristosscripts.
37ca32bd8dSchristos.Pp
38ca32bd8dSchristos.Nm
39ca32bd8dSchristosuses non-blocking socket I/O to contact as many hosts as possible in
40ca32bd8dSchristosparallel, so it is very efficient.
41ca32bd8dSchristosThe keys from a domain of 1,000
42ca32bd8dSchristoshosts can be collected in tens of seconds, even when some of those
43ffae97bbSchristoshosts are down or do not run
44ffae97bbSchristos.Xr sshd 8 .
45ca32bd8dSchristosFor scanning, one does not need
46ca32bd8dSchristoslogin access to the machines that are being scanned, nor does the
47ca32bd8dSchristosscanning process involve any encryption.
48ca32bd8dSchristos.Pp
49b1066cf3SchristosHosts to be scanned may be specified by hostname, address or by CIDR
50b1066cf3Schristosnetwork range (e.g. 192.168.16/28).
51b1066cf3SchristosIf a network range is specified, then all addresses in that range will
52b1066cf3Schristosbe scanned.
53b1066cf3Schristos.Pp
54ca32bd8dSchristosThe options are as follows:
55ca32bd8dSchristos.Bl -tag -width Ds
56ca32bd8dSchristos.It Fl 4
57ffae97bbSchristosForce
58ca32bd8dSchristos.Nm
59ca32bd8dSchristosto use IPv4 addresses only.
60ca32bd8dSchristos.It Fl 6
61ffae97bbSchristosForce
62ca32bd8dSchristos.Nm
63ca32bd8dSchristosto use IPv6 addresses only.
6479976551Schristos.It Fl c
6579976551SchristosRequest certificates from target hosts instead of plain keys.
66ffae97bbSchristos.It Fl D
67ffae97bbSchristosPrint keys found as SSHFP DNS records.
68ffae97bbSchristosThe default is to print keys in a format usable as a
69ffae97bbSchristos.Xr ssh 1
70ffae97bbSchristos.Pa known_hosts
71ffae97bbSchristosfile.
72ca32bd8dSchristos.It Fl f Ar file
73ca32bd8dSchristosRead hosts or
748a4530f9Schristos.Dq addrlist namelist
758a4530f9Schristospairs from
768a4530f9Schristos.Ar file ,
778a4530f9Schristosone per line.
78ca32bd8dSchristosIf
79ffae97bbSchristos.Sq -
80ca32bd8dSchristosis supplied instead of a filename,
81ca32bd8dSchristos.Nm
82ffae97bbSchristoswill read from the standard input.
83b1066cf3SchristosNames read from a file must start with an address, hostname or CIDR network
84b1066cf3Schristosrange to be scanned.
85b1066cf3SchristosAddresses and hostnames may optionally be followed by comma-separated name
86b1066cf3Schristosor address aliases that will be copied to the output.
87b1066cf3SchristosFor example:
88ffae97bbSchristos.Bd -literal
89b1066cf3Schristos192.168.11.0/24
90b1066cf3Schristos10.20.1.1
91b1066cf3Schristoshappy.example.org
92b1066cf3Schristos10.0.0.1,sad.example.org
93ffae97bbSchristos.Ed
94ca32bd8dSchristos.It Fl H
95ca32bd8dSchristosHash all hostnames and addresses in the output.
96ca32bd8dSchristosHashed names may be used normally by
97ffae97bbSchristos.Xr ssh 1
98ca32bd8dSchristosand
99ffae97bbSchristos.Xr sshd 8 ,
100ca32bd8dSchristosbut they do not reveal identifying information should the file's contents
101ca32bd8dSchristosbe disclosed.
102b1066cf3Schristos.It Fl O Ar option
103b1066cf3SchristosSpecify a key/value option.
104b1066cf3SchristosAt present, only a single option is supported:
105b1066cf3Schristos.Bl -tag -width Ds
106b1066cf3Schristos.It Cm hashalg Ns = Ns Ar algorithm
107b1066cf3SchristosSelects a hash algorithm to use when printing SSHFP records using the
108b1066cf3Schristos.Fl D
109b1066cf3Schristosflag.
110b1066cf3SchristosValid algorithms are
111b1066cf3Schristos.Dq sha1
112b1066cf3Schristosand
113b1066cf3Schristos.Dq sha256 .
114b1066cf3SchristosThe default is to print both.
115b1066cf3Schristos.El
116ca32bd8dSchristos.It Fl p Ar port
117ffae97bbSchristosConnect to
118ffae97bbSchristos.Ar port
119ffae97bbSchristoson the remote host.
120*1c7715ddSchristos.It Fl q
121*1c7715ddSchristosQuiet mode:
122*1c7715ddSchristosdo not print server host name and banners in comments.
123ca32bd8dSchristos.It Fl T Ar timeout
124ca32bd8dSchristosSet the timeout for connection attempts.
125ca32bd8dSchristosIf
1268a4530f9Schristos.Ar timeout
127ca32bd8dSchristosseconds have elapsed since a connection was initiated to a host or since the
128ffae97bbSchristoslast time anything was read from that host, the connection is
129ca32bd8dSchristosclosed and the host in question considered unavailable.
130ffae97bbSchristosThe default is 5 seconds.
131ca32bd8dSchristos.It Fl t Ar type
132ffae97bbSchristosSpecify the type of the key to fetch from the scanned hosts.
133ca32bd8dSchristosThe possible values are
1348a4530f9Schristos.Dq ecdsa ,
1358a4530f9Schristos.Dq ed25519 ,
136e160b4e8Schristos.Dq ecdsa-sk ,
137e160b4e8Schristos.Dq ed25519-sk ,
138ca32bd8dSchristosor
1397a183406Schristos.Dq rsa .
140ca32bd8dSchristosMultiple values may be specified by separating them with commas.
141*1c7715ddSchristosThe default is to fetch all the above key types.
142ca32bd8dSchristos.It Fl v
143ffae97bbSchristosVerbose mode:
144ffae97bbSchristosprint debugging messages about progress.
145ca32bd8dSchristos.El
146ffae97bbSchristos.Pp
147ca32bd8dSchristosIf an ssh_known_hosts file is constructed using
148ca32bd8dSchristos.Nm
149ca32bd8dSchristoswithout verifying the keys, users will be vulnerable to
150ca32bd8dSchristos.Em man in the middle
151ca32bd8dSchristosattacks.
152ca32bd8dSchristosOn the other hand, if the security model allows such a risk,
153ca32bd8dSchristos.Nm
154ca32bd8dSchristoscan help in the detection of tampered keyfiles or man in the middle
155ca32bd8dSchristosattacks which have begun after the ssh_known_hosts file was created.
156ca32bd8dSchristos.Sh FILES
157ca32bd8dSchristos.Pa /etc/ssh/ssh_known_hosts
158ca32bd8dSchristos.Sh EXAMPLES
159ffae97bbSchristosPrint the RSA host key for machine
1608a4530f9Schristos.Ar hostname :
161ffae97bbSchristos.Pp
162ffae97bbSchristos.Dl $ ssh-keyscan -t rsa hostname
163ca32bd8dSchristos.Pp
164b1066cf3SchristosSearch a network range, printing all supported key types:
165b1066cf3Schristos.Pp
166b1066cf3Schristos.Dl $ ssh-keyscan 192.168.0.64/25
167b1066cf3Schristos.Pp
168ca32bd8dSchristosFind all hosts from the file
169ca32bd8dSchristos.Pa ssh_hosts
170ca32bd8dSchristoswhich have new or different keys from those in the sorted file
171ca32bd8dSchristos.Pa ssh_known_hosts :
172ffae97bbSchristos.Bd -literal -offset indent
173*1c7715ddSchristos$ ssh-keyscan -t rsa,ecdsa,ed25519 -f ssh_hosts | \e
174ca32bd8dSchristos	sort -u - ssh_known_hosts | diff ssh_known_hosts -
175ca32bd8dSchristos.Ed
176ca32bd8dSchristos.Sh SEE ALSO
177ca32bd8dSchristos.Xr ssh 1 ,
178ca32bd8dSchristos.Xr sshd 8
179ffae97bbSchristos.Rs
180ffae97bbSchristos.%D 2006
181ffae97bbSchristos.%R RFC 4255
182ffae97bbSchristos.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
183ffae97bbSchristos.Re
184ca32bd8dSchristos.Sh AUTHORS
185ca32bd8dSchristos.An -nosplit
186a5684d07Swiz.An David Mazieres Aq Mt dm@lcs.mit.edu
187ca32bd8dSchristoswrote the initial version, and
188a5684d07Swiz.An Wayne Davison Aq Mt wayned@users.sourceforge.net
189ca32bd8dSchristosadded support for protocol version 2.
190