xref: /netbsd-src/crypto/external/bsd/openssh/dist/ssh-keyscan.1 (revision 7d62b00eb9ad855ffcd7da46b41e23feb5476fac)
1.\"	$NetBSD: ssh-keyscan.1,v 1.17 2022/10/05 22:39:36 christos Exp $
2.\"	$OpenBSD: ssh-keyscan.1,v 1.46 2022/06/03 04:00:15 dtucker Exp $
3.\"
4.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
5.\"
6.\" Modification and redistribution in source and binary forms is
7.\" permitted provided that due credit is given to the author and the
8.\" OpenBSD project by leaving this copyright notice intact.
9.\"
10.Dd June 3 2022
11.Dt SSH-KEYSCAN 1
12.Os
13.Sh NAME
14.Nm ssh-keyscan
15.Nd gather SSH public keys from servers
16.Sh SYNOPSIS
17.Nm ssh-keyscan
18.Op Fl 46cDHv
19.Op Fl f Ar file
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
48The options are as follows:
49.Bl -tag -width Ds
50.It Fl 4
51Force
52.Nm
53to use IPv4 addresses only.
54.It Fl 6
55Force
56.Nm
57to use IPv6 addresses only.
58.It Fl c
59Request certificates from target hosts instead of plain keys.
60.It Fl D
61Print keys found as SSHFP DNS records.
62The default is to print keys in a format usable as a
63.Xr ssh 1
64.Pa known_hosts
65file.
66.It Fl f Ar file
67Read hosts or
68.Dq addrlist namelist
69pairs from
70.Ar file ,
71one per line.
72If
73.Sq -
74is supplied instead of a filename,
75.Nm
76will read from the standard input.
77Input is expected in the format:
78.Bd -literal
791.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4
80.Ed
81.It Fl H
82Hash all hostnames and addresses in the output.
83Hashed names may be used normally by
84.Xr ssh 1
85and
86.Xr sshd 8 ,
87but they do not reveal identifying information should the file's contents
88be disclosed.
89.It Fl p Ar port
90Connect to
91.Ar port
92on the remote host.
93.It Fl T Ar timeout
94Set the timeout for connection attempts.
95If
96.Ar timeout
97seconds have elapsed since a connection was initiated to a host or since the
98last time anything was read from that host, the connection is
99closed and the host in question considered unavailable.
100The default is 5 seconds.
101.It Fl t Ar type
102Specify the type of the key to fetch from the scanned hosts.
103The possible values are
104.Dq dsa ,
105.Dq ecdsa ,
106.Dq ed25519 ,
107.Dq ecdsa-sk ,
108.Dq ed25519-sk ,
109or
110.Dq rsa .
111Multiple values may be specified by separating them with commas.
112The default is to fetch
113.Dq rsa ,
114.Dq ecdsa ,
115.Dq ed25519 ,
116.Dq ecdsa-sk ,
117and
118.Dq ed25519-sk
119keys.
120.It Fl v
121Verbose mode:
122print debugging messages about progress.
123.El
124.Pp
125If an ssh_known_hosts file is constructed using
126.Nm
127without verifying the keys, users will be vulnerable to
128.Em man in the middle
129attacks.
130On the other hand, if the security model allows such a risk,
131.Nm
132can help in the detection of tampered keyfiles or man in the middle
133attacks which have begun after the ssh_known_hosts file was created.
134.Sh FILES
135.Pa /etc/ssh/ssh_known_hosts
136.Sh EXAMPLES
137Print the RSA host key for machine
138.Ar hostname :
139.Pp
140.Dl $ ssh-keyscan -t rsa hostname
141.Pp
142Find all hosts from the file
143.Pa ssh_hosts
144which have new or different keys from those in the sorted file
145.Pa ssh_known_hosts :
146.Bd -literal -offset indent
147$ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e
148	sort -u - ssh_known_hosts | diff ssh_known_hosts -
149.Ed
150.Sh SEE ALSO
151.Xr ssh 1 ,
152.Xr sshd 8
153.Rs
154.%D 2006
155.%R RFC 4255
156.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
157.Re
158.Sh AUTHORS
159.An -nosplit
160.An David Mazieres Aq Mt dm@lcs.mit.edu
161wrote the initial version, and
162.An Wayne Davison Aq Mt wayned@users.sourceforge.net
163added support for protocol version 2.
164