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