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