]> git.ipfire.org Git - thirdparty/openssh-portable.git/blob - ssh-keyscan.1
upstream: Factor out PuTTY setup.
[thirdparty/openssh-portable.git] / ssh-keyscan.1
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
26 is a utility for gathering the public SSH host keys of a number of
27 hosts.
28 It was designed to aid in building and verifying
29 .Pa ssh_known_hosts
30 files,
31 the format of which is documented in
32 .Xr sshd 8 .
33 .Nm
34 provides a minimal interface suitable for use by shell and perl
35 scripts.
36 .Pp
37 .Nm
38 uses non-blocking socket I/O to contact as many hosts as possible in
39 parallel, so it is very efficient.
40 The keys from a domain of 1,000
41 hosts can be collected in tens of seconds, even when some of those
42 hosts are down or do not run
43 .Xr sshd 8 .
44 For scanning, one does not need
45 login access to the machines that are being scanned, nor does the
46 scanning process involve any encryption.
47 .Pp
48 Hosts to be scanned may be specified by hostname, address or by CIDR
49 network range (e.g. 192.168.16/28).
50 If a network range is specified, then all addresses in that range will
51 be scanned.
52 .Pp
53 The options are as follows:
54 .Bl -tag -width Ds
55 .It Fl 4
56 Force
57 .Nm
58 to use IPv4 addresses only.
59 .It Fl 6
60 Force
61 .Nm
62 to use IPv6 addresses only.
63 .It Fl c
64 Request certificates from target hosts instead of plain keys.
65 .It Fl D
66 Print keys found as SSHFP DNS records.
67 The default is to print keys in a format usable as a
68 .Xr ssh 1
69 .Pa known_hosts
70 file.
71 .It Fl f Ar file
72 Read hosts or
73 .Dq addrlist namelist
74 pairs from
75 .Ar file ,
76 one per line.
77 If
78 .Sq -
79 is supplied instead of a filename,
80 .Nm
81 will read from the standard input.
82 Names read from a file must start with an address, hostname or CIDR network
83 range to be scanned.
84 Addresses and hostnames may optionally be followed by comma-separated name
85 or address aliases that will be copied to the output.
86 For example:
87 .Bd -literal
88 192.168.11.0/24
89 10.20.1.1
90 happy.example.org
91 10.0.0.1,sad.example.org
92 .Ed
93 .It Fl H
94 Hash all hostnames and addresses in the output.
95 Hashed names may be used normally by
96 .Xr ssh 1
97 and
98 .Xr sshd 8 ,
99 but they do not reveal identifying information should the file's contents
100 be disclosed.
101 .It Fl O Ar option
102 Specify a key/value option.
103 At present, only a single option is supported:
104 .Bl -tag -width Ds
105 .It Cm hashalg Ns = Ns Ar algorithm
106 Selects a hash algorithm to use when printing SSHFP records using the
107 .Fl D
108 flag.
109 Valid algorithms are
110 .Dq sha1
111 and
112 .Dq sha256 .
113 The default is to print both.
114 .El
115 .It Fl p Ar port
116 Connect to
117 .Ar port
118 on the remote host.
119 .It Fl T Ar timeout
120 Set the timeout for connection attempts.
121 If
122 .Ar timeout
123 seconds have elapsed since a connection was initiated to a host or since the
124 last time anything was read from that host, the connection is
125 closed and the host in question considered unavailable.
126 The default is 5 seconds.
127 .It Fl t Ar type
128 Specify the type of the key to fetch from the scanned hosts.
129 The possible values are
130 .Dq dsa ,
131 .Dq ecdsa ,
132 .Dq ed25519 ,
133 .Dq ecdsa-sk ,
134 .Dq ed25519-sk ,
135 or
136 .Dq rsa .
137 Multiple values may be specified by separating them with commas.
138 The default is to fetch
139 .Dq rsa ,
140 .Dq ecdsa ,
141 .Dq ed25519 ,
142 .Dq ecdsa-sk ,
143 and
144 .Dq ed25519-sk
145 keys.
146 .It Fl v
147 Verbose mode:
148 print debugging messages about progress.
149 .El
150 .Pp
151 If an ssh_known_hosts file is constructed using
152 .Nm
153 without verifying the keys, users will be vulnerable to
154 .Em man in the middle
155 attacks.
156 On the other hand, if the security model allows such a risk,
157 .Nm
158 can help in the detection of tampered keyfiles or man in the middle
159 attacks which have begun after the ssh_known_hosts file was created.
160 .Sh FILES
161 .Pa /etc/ssh/ssh_known_hosts
162 .Sh EXAMPLES
163 Print the RSA host key for machine
164 .Ar hostname :
165 .Pp
166 .Dl $ ssh-keyscan -t rsa hostname
167 .Pp
168 Search a network range, printing all supported key types:
169 .Pp
170 .Dl $ ssh-keyscan 192.168.0.64/25
171 .Pp
172 Find all hosts from the file
173 .Pa ssh_hosts
174 which 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
191 wrote the initial version, and
192 .An Wayne Davison Aq Mt wayned@users.sourceforge.net
193 added support for protocol version 2.