blob: f9df75d42f1ad1e79770df4120091b03b96d97ef [file] [log] [blame]
jmc@openbsd.org483cc722019-11-30 07:07:59 +00001.\" $OpenBSD: ssh-keyscan.1,v 1.45 2019/11/30 07:07:59 jmc Exp $
Ben Lindstromb22c2b82001-03-05 06:50:47 +00002.\"
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
Ben Lindstroma238f6e2001-06-09 01:30:39 +00007.\" OpenBSD project by leaving this copyright notice intact.
Ben Lindstrom36579d32001-01-29 07:39:26 +00008.\"
jmc@openbsd.org483cc722019-11-30 07:07:59 +00009.Dd $Mdocdate: November 30 2019 $
Ben Lindstromb22c2b82001-03-05 06:50:47 +000010.Dt SSH-KEYSCAN 1
Ben Lindstromb6434ae2000-12-05 01:15:09 +000011.Os
12.Sh NAME
13.Nm ssh-keyscan
jmc@openbsd.org483cc722019-11-30 07:07:59 +000014.Nd gather SSH public keys from servers
Ben Lindstromb6434ae2000-12-05 01:15:09 +000015.Sh SYNOPSIS
16.Nm ssh-keyscan
djm@openbsd.org1a348352018-02-23 05:14:05 +000017.Op Fl 46cDHv
Damien Miller9a2fdbd2005-03-02 12:04:01 +110018.Op Fl f Ar file
Ben Lindstrom325e70c2001-08-06 22:41:30 +000019.Op Fl p Ar port
20.Op Fl T Ar timeout
21.Op Fl t Ar type
Ben Lindstrom325e70c2001-08-06 22:41:30 +000022.Op Ar host | addrlist namelist
Ben Lindstromb6434ae2000-12-05 01:15:09 +000023.Sh DESCRIPTION
24.Nm
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000025is a utility for gathering the public SSH host keys of a number of
Damien Miller495dca32003-04-01 21:42:14 +100026hosts.
27It was designed to aid in building and verifying
Ben Lindstromb6434ae2000-12-05 01:15:09 +000028.Pa ssh_known_hosts
jmc@openbsd.org0bcd8712018-03-05 07:03:18 +000029files,
30the format of which is documented in
31.Xr sshd 8 .
Ben Lindstromb6434ae2000-12-05 01:15:09 +000032.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
Damien Miller495dca32003-04-01 21:42:14 +100038parallel, so it is very efficient.
39The keys from a domain of 1,000
Ben Lindstromb6434ae2000-12-05 01:15:09 +000040hosts can be collected in tens of seconds, even when some of those
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000041hosts are down or do not run
42.Xr sshd 8 .
Damien Miller495dca32003-04-01 21:42:14 +100043For scanning, one does not need
Ben Lindstrom594e2032001-09-12 18:35:30 +000044login access to the machines that are being scanned, nor does the
45scanning process involve any encryption.
Ben Lindstrom0b5afb92001-08-06 22:01:29 +000046.Pp
47The options are as follows:
Ben Lindstromb6434ae2000-12-05 01:15:09 +000048.Bl -tag -width Ds
Damien Miller9a2fdbd2005-03-02 12:04:01 +110049.It Fl 4
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000050Force
Damien Miller9a2fdbd2005-03-02 12:04:01 +110051.Nm
52to use IPv4 addresses only.
53.It Fl 6
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000054Force
Damien Miller9a2fdbd2005-03-02 12:04:01 +110055.Nm
56to use IPv6 addresses only.
djm@openbsd.org3a424cd2015-11-08 22:30:20 +000057.It Fl c
58Request certificates from target hosts instead of plain keys.
djm@openbsd.org1a348352018-02-23 05:14:05 +000059.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.
Damien Miller9a2fdbd2005-03-02 12:04:01 +110065.It Fl f Ar file
66Read hosts or
Damien Millerf8f35bc2014-02-04 11:09:12 +110067.Dq addrlist namelist
68pairs from
69.Ar file ,
70one per line.
Damien Miller9a2fdbd2005-03-02 12:04:01 +110071If
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000072.Sq -
Damien Miller9a2fdbd2005-03-02 12:04:01 +110073is supplied instead of a filename,
74.Nm
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000075will read from the standard input.
jmc@openbsd.org0bcd8712018-03-05 07:03:18 +000076Input 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
Damien Millerdb7b8172005-03-01 21:48:03 +110080.It Fl H
81Hash all hostnames and addresses in the output.
82Hashed names may be used normally by
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000083.Xr ssh 1
Damien Millerdb7b8172005-03-01 21:48:03 +110084and
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000085.Xr sshd 8 ,
Damien Millerdb7b8172005-03-01 21:48:03 +110086but they do not reveal identifying information should the file's contents
87be disclosed.
Ben Lindstrom325e70c2001-08-06 22:41:30 +000088.It Fl p Ar port
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000089Connect to
90.Ar port
91on the remote host.
Ben Lindstrom8d066fb2001-09-12 17:06:13 +000092.It Fl T Ar timeout
Damien Miller495dca32003-04-01 21:42:14 +100093Set the timeout for connection attempts.
94If
Damien Millerf8f35bc2014-02-04 11:09:12 +110095.Ar timeout
Ben Lindstromb6434ae2000-12-05 01:15:09 +000096seconds have elapsed since a connection was initiated to a host or since the
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000097last time anything was read from that host, the connection is
Damien Miller495dca32003-04-01 21:42:14 +100098closed and the host in question considered unavailable.
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000099The default is 5 seconds.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000100.It Fl t Ar type
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000101Specify the type of the key to fetch from the scanned hosts.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000102The possible values are
Damien Millereb8b60e2010-08-31 22:41:14 +1000103.Dq dsa ,
Damien Miller8ba0ead2013-12-18 17:46:27 +1100104.Dq ecdsa ,
105.Dq ed25519 ,
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000106or
jmc@openbsd.orgf10c0d32017-05-02 17:04:09 +0000107.Dq rsa .
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000108Multiple values may be specified by separating them with commas.
Damien Miller839f7432012-04-22 11:24:21 +1000109The default is to fetch
Damien Miller94bfe0f2014-04-20 13:00:51 +1000110.Dq rsa ,
111.Dq ecdsa ,
Damien Miller839f7432012-04-22 11:24:21 +1000112and
Damien Miller94bfe0f2014-04-20 13:00:51 +1000113.Dq ed25519
Damien Miller839f7432012-04-22 11:24:21 +1000114keys.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000115.It Fl v
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000116Verbose mode:
117print debugging messages about progress.
Ben Lindstromd26dcf32001-01-06 15:18:16 +0000118.El
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000119.Pp
Darren Tuckerffe88e12006-10-18 07:53:06 +1000120If an ssh_known_hosts file is constructed using
Ben Lindstrom0b5afb92001-08-06 22:01:29 +0000121.Nm
Ben Lindstrom594e2032001-09-12 18:35:30 +0000122without verifying the keys, users will be vulnerable to
Darren Tucker3ca45082004-07-17 16:13:15 +1000123.Em man in the middle
Ben Lindstrom0b5afb92001-08-06 22:01:29 +0000124attacks.
Ben Lindstrom594e2032001-09-12 18:35:30 +0000125On the other hand, if the security model allows such a risk,
Ben Lindstrom0b5afb92001-08-06 22:01:29 +0000126.Nm
Ben Lindstrom594e2032001-09-12 18:35:30 +0000127can help in the detection of tampered keyfiles or man in the middle
128attacks which have begun after the ssh_known_hosts file was created.
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000129.Sh FILES
Damien Miller05eda432002-02-10 18:32:28 +1100130.Pa /etc/ssh/ssh_known_hosts
Damien Millerf1ce5052003-06-11 22:04:39 +1000131.Sh EXAMPLES
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000132Print the RSA host key for machine
Damien Millerf8f35bc2014-02-04 11:09:12 +1100133.Ar hostname :
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000134.Pp
135.Dl $ ssh-keyscan -t rsa hostname
Damien Millerf1ce5052003-06-11 22:04:39 +1000136.Pp
137Find all hosts from the file
138.Pa ssh_hosts
139which have new or different keys from those in the sorted file
140.Pa ssh_known_hosts :
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000141.Bd -literal -offset indent
Damien Miller94bfe0f2014-04-20 13:00:51 +1000142$ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e
Damien Millerf1ce5052003-06-11 22:04:39 +1000143 sort -u - ssh_known_hosts | diff ssh_known_hosts -
144.Ed
145.Sh SEE ALSO
146.Xr ssh 1 ,
147.Xr sshd 8
jmc@openbsd.org7d330a12018-02-23 07:38:09 +0000148.Rs
djm@openbsd.org1a348352018-02-23 05:14:05 +0000149.%D 2006
jmc@openbsd.org7d330a12018-02-23 07:38:09 +0000150.%R RFC 4255
151.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
djm@openbsd.org1a348352018-02-23 05:14:05 +0000152.Re
Damien Millerf1ce5052003-06-11 22:04:39 +1000153.Sh AUTHORS
Darren Tucker28e8e592005-10-03 18:20:28 +1000154.An -nosplit
Damien Millerbf836e52013-07-18 16:14:13 +1000155.An David Mazieres Aq Mt dm@lcs.mit.edu
Damien Millerf1ce5052003-06-11 22:04:39 +1000156wrote the initial version, and
Damien Millerbf836e52013-07-18 16:14:13 +1000157.An Wayne Davison Aq Mt wayned@users.sourceforge.net
Damien Millerf1ce5052003-06-11 22:04:39 +1000158added support for protocol version 2.