xref: /freebsd/crypto/openssh/ssh-keyscan.1 (revision 4543ef516683042d46f3bd3bb8a4f3f746e00499)
1.\"	$OpenBSD: ssh-keyscan.1,v 1.49 2023/02/10 06:41:53 jmc 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: February 10 2023 $
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 46cDHv
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
53The options are as follows:
54.Bl -tag -width Ds
55.It Fl 4
56Force
57.Nm
58to use IPv4 addresses only.
59.It Fl 6
60Force
61.Nm
62to use IPv6 addresses only.
63.It Fl c
64Request certificates from target hosts instead of plain keys.
65.It Fl D
66Print keys found as SSHFP DNS records.
67The default is to print keys in a format usable as a
68.Xr ssh 1
69.Pa known_hosts
70file.
71.It Fl f Ar file
72Read hosts or
73.Dq addrlist namelist
74pairs from
75.Ar file ,
76one per line.
77If
78.Sq -
79is supplied instead of a filename,
80.Nm
81will read from the standard input.
82Names read from a file must start with an address, hostname or CIDR network
83range to be scanned.
84Addresses and hostnames may optionally be followed by comma-separated name
85or address aliases that will be copied to the output.
86For example:
87.Bd -literal
88192.168.11.0/24
8910.20.1.1
90happy.example.org
9110.0.0.1,sad.example.org
92.Ed
93.It Fl H
94Hash all hostnames and addresses in the output.
95Hashed names may be used normally by
96.Xr ssh 1
97and
98.Xr sshd 8 ,
99but they do not reveal identifying information should the file's contents
100be disclosed.
101.It Fl O Ar option
102Specify a key/value option.
103At present, only a single option is supported:
104.Bl -tag -width Ds
105.It Cm hashalg Ns = Ns Ar algorithm
106Selects a hash algorithm to use when printing SSHFP records using the
107.Fl D
108flag.
109Valid algorithms are
110.Dq sha1
111and
112.Dq sha256 .
113The default is to print both.
114.El
115.It Fl p Ar port
116Connect to
117.Ar port
118on the remote host.
119.It Fl T Ar timeout
120Set the timeout for connection attempts.
121If
122.Ar timeout
123seconds have elapsed since a connection was initiated to a host or since the
124last time anything was read from that host, the connection is
125closed and the host in question considered unavailable.
126The default is 5 seconds.
127.It Fl t Ar type
128Specify the type of the key to fetch from the scanned hosts.
129The possible values are
130.Dq dsa ,
131.Dq ecdsa ,
132.Dq ed25519 ,
133.Dq ecdsa-sk ,
134.Dq ed25519-sk ,
135or
136.Dq rsa .
137Multiple values may be specified by separating them with commas.
138The default is to fetch
139.Dq rsa ,
140.Dq ecdsa ,
141.Dq ed25519 ,
142.Dq ecdsa-sk ,
143and
144.Dq ed25519-sk
145keys.
146.It Fl v
147Verbose mode:
148print debugging messages about progress.
149.El
150.Pp
151If an ssh_known_hosts file is constructed using
152.Nm
153without verifying the keys, users will be vulnerable to
154.Em man in the middle
155attacks.
156On the other hand, if the security model allows such a risk,
157.Nm
158can help in the detection of tampered keyfiles or man in the middle
159attacks which have begun after the ssh_known_hosts file was created.
160.Sh FILES
161.Pa /etc/ssh/ssh_known_hosts
162.Sh EXAMPLES
163Print the RSA host key for machine
164.Ar hostname :
165.Pp
166.Dl $ ssh-keyscan -t rsa hostname
167.Pp
168Search a network range, printing all supported key types:
169.Pp
170.Dl $ ssh-keyscan 192.168.0.64/25
171.Pp
172Find all hosts from the file
173.Pa ssh_hosts
174which have new or different keys from those in the sorted file
175.Pa ssh_known_hosts :
176.Bd -literal -offset indent
177$ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e
178	sort -u - ssh_known_hosts | diff ssh_known_hosts -
179.Ed
180.Sh SEE ALSO
181.Xr ssh 1 ,
182.Xr sshd 8
183.Rs
184.%D 2006
185.%R RFC 4255
186.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
187.Re
188.Sh AUTHORS
189.An -nosplit
190.An David Mazieres Aq Mt dm@lcs.mit.edu
191wrote the initial version, and
192.An Wayne Davison Aq Mt wayned@users.sourceforge.net
193added support for protocol version 2.
194