blob: edefe76f6d0d0abba5cd92956cfc37e3e948b8ad [file] [log] [blame]
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +00001.\" $OpenBSD: ssh-keyscan.1,v 1.43 2018/03/02 21:40:15 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.orgf493d2b2018-03-02 21:40:15 +00009.Dd $Mdocdate: March 2 2018 $
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.orgf493d2b2018-03-02 21:40:15 +000014.Nd gather SSH public keys
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
29files.
30.Nm
31provides a minimal interface suitable for use by shell and perl
32scripts.
33.Pp
34.Nm
35uses non-blocking socket I/O to contact as many hosts as possible in
Damien Miller495dca32003-04-01 21:42:14 +100036parallel, so it is very efficient.
37The keys from a domain of 1,000
Ben Lindstromb6434ae2000-12-05 01:15:09 +000038hosts can be collected in tens of seconds, even when some of those
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000039hosts are down or do not run
40.Xr sshd 8 .
Damien Miller495dca32003-04-01 21:42:14 +100041For scanning, one does not need
Ben Lindstrom594e2032001-09-12 18:35:30 +000042login access to the machines that are being scanned, nor does the
43scanning process involve any encryption.
Ben Lindstrom0b5afb92001-08-06 22:01:29 +000044.Pp
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000045Input is expected in the format:
46.Bd -literal -offset 3n
471.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4
48.Ed
49.Pp
50The output format is:
51.Bd -literal -offset 3n
52host-or-namelist keytype base64-encoded-key
53.Ed
54.Pp
55Where
56.Ar keytype
57is either
58.Dq ecdsa-sha2-nistp256 ,
59.Dq ecdsa-sha2-nistp384 ,
60.Dq ecdsa-sha2-nistp521 ,
61.Dq ssh-ed25519 ,
62.Dq ssh-dss
63or
64.Dq ssh-rsa .
65.Pp
Ben Lindstrom0b5afb92001-08-06 22:01:29 +000066The options are as follows:
Ben Lindstromb6434ae2000-12-05 01:15:09 +000067.Bl -tag -width Ds
Damien Miller9a2fdbd2005-03-02 12:04:01 +110068.It Fl 4
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000069Force
Damien Miller9a2fdbd2005-03-02 12:04:01 +110070.Nm
71to use IPv4 addresses only.
72.It Fl 6
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000073Force
Damien Miller9a2fdbd2005-03-02 12:04:01 +110074.Nm
75to use IPv6 addresses only.
djm@openbsd.org3a424cd2015-11-08 22:30:20 +000076.It Fl c
77Request certificates from target hosts instead of plain keys.
djm@openbsd.org1a348352018-02-23 05:14:05 +000078.It Fl D
79Print keys found as SSHFP DNS records.
80The default is to print keys in a format usable as a
81.Xr ssh 1
82.Pa known_hosts
83file.
Damien Miller9a2fdbd2005-03-02 12:04:01 +110084.It Fl f Ar file
85Read hosts or
Damien Millerf8f35bc2014-02-04 11:09:12 +110086.Dq addrlist namelist
87pairs from
88.Ar file ,
89one per line.
Damien Miller9a2fdbd2005-03-02 12:04:01 +110090If
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000091.Sq -
Damien Miller9a2fdbd2005-03-02 12:04:01 +110092is supplied instead of a filename,
93.Nm
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000094will read from the standard input.
Damien Millerdb7b8172005-03-01 21:48:03 +110095.It Fl H
96Hash all hostnames and addresses in the output.
97Hashed names may be used normally by
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +000098.Xr ssh 1
Damien Millerdb7b8172005-03-01 21:48:03 +110099and
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000100.Xr sshd 8 ,
Damien Millerdb7b8172005-03-01 21:48:03 +1100101but they do not reveal identifying information should the file's contents
102be disclosed.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000103.It Fl p Ar port
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000104Connect to
105.Ar port
106on the remote host.
Ben Lindstrom8d066fb2001-09-12 17:06:13 +0000107.It Fl T Ar timeout
Damien Miller495dca32003-04-01 21:42:14 +1000108Set the timeout for connection attempts.
109If
Damien Millerf8f35bc2014-02-04 11:09:12 +1100110.Ar timeout
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000111seconds have elapsed since a connection was initiated to a host or since the
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000112last time anything was read from that host, the connection is
Damien Miller495dca32003-04-01 21:42:14 +1000113closed and the host in question considered unavailable.
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000114The default is 5 seconds.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000115.It Fl t Ar type
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000116Specify the type of the key to fetch from the scanned hosts.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000117The possible values are
Damien Millereb8b60e2010-08-31 22:41:14 +1000118.Dq dsa ,
Damien Miller8ba0ead2013-12-18 17:46:27 +1100119.Dq ecdsa ,
120.Dq ed25519 ,
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000121or
jmc@openbsd.orgf10c0d32017-05-02 17:04:09 +0000122.Dq rsa .
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000123Multiple values may be specified by separating them with commas.
Damien Miller839f7432012-04-22 11:24:21 +1000124The default is to fetch
Damien Miller94bfe0f2014-04-20 13:00:51 +1000125.Dq rsa ,
126.Dq ecdsa ,
Damien Miller839f7432012-04-22 11:24:21 +1000127and
Damien Miller94bfe0f2014-04-20 13:00:51 +1000128.Dq ed25519
Damien Miller839f7432012-04-22 11:24:21 +1000129keys.
Ben Lindstrom325e70c2001-08-06 22:41:30 +0000130.It Fl v
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000131Verbose mode:
132print debugging messages about progress.
Ben Lindstromd26dcf32001-01-06 15:18:16 +0000133.El
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000134.Pp
Darren Tuckerffe88e12006-10-18 07:53:06 +1000135If an ssh_known_hosts file is constructed using
Ben Lindstrom0b5afb92001-08-06 22:01:29 +0000136.Nm
Ben Lindstrom594e2032001-09-12 18:35:30 +0000137without verifying the keys, users will be vulnerable to
Darren Tucker3ca45082004-07-17 16:13:15 +1000138.Em man in the middle
Ben Lindstrom0b5afb92001-08-06 22:01:29 +0000139attacks.
Ben Lindstrom594e2032001-09-12 18:35:30 +0000140On the other hand, if the security model allows such a risk,
Ben Lindstrom0b5afb92001-08-06 22:01:29 +0000141.Nm
Ben Lindstrom594e2032001-09-12 18:35:30 +0000142can help in the detection of tampered keyfiles or man in the middle
143attacks which have begun after the ssh_known_hosts file was created.
Ben Lindstromb6434ae2000-12-05 01:15:09 +0000144.Sh FILES
Damien Miller05eda432002-02-10 18:32:28 +1100145.Pa /etc/ssh/ssh_known_hosts
Damien Millerf1ce5052003-06-11 22:04:39 +1000146.Sh EXAMPLES
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000147Print the RSA host key for machine
Damien Millerf8f35bc2014-02-04 11:09:12 +1100148.Ar hostname :
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000149.Pp
150.Dl $ ssh-keyscan -t rsa hostname
Damien Millerf1ce5052003-06-11 22:04:39 +1000151.Pp
152Find all hosts from the file
153.Pa ssh_hosts
154which have new or different keys from those in the sorted file
155.Pa ssh_known_hosts :
jmc@openbsd.orgf493d2b2018-03-02 21:40:15 +0000156.Bd -literal -offset indent
Damien Miller94bfe0f2014-04-20 13:00:51 +1000157$ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e
Damien Millerf1ce5052003-06-11 22:04:39 +1000158 sort -u - ssh_known_hosts | diff ssh_known_hosts -
159.Ed
160.Sh SEE ALSO
161.Xr ssh 1 ,
162.Xr sshd 8
jmc@openbsd.org7d330a12018-02-23 07:38:09 +0000163.Rs
djm@openbsd.org1a348352018-02-23 05:14:05 +0000164.%D 2006
jmc@openbsd.org7d330a12018-02-23 07:38:09 +0000165.%R RFC 4255
166.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
djm@openbsd.org1a348352018-02-23 05:14:05 +0000167.Re
Damien Millerf1ce5052003-06-11 22:04:39 +1000168.Sh AUTHORS
Darren Tucker28e8e592005-10-03 18:20:28 +1000169.An -nosplit
Damien Millerbf836e52013-07-18 16:14:13 +1000170.An David Mazieres Aq Mt dm@lcs.mit.edu
Damien Millerf1ce5052003-06-11 22:04:39 +1000171wrote the initial version, and
Damien Millerbf836e52013-07-18 16:14:13 +1000172.An Wayne Davison Aq Mt wayned@users.sourceforge.net
Damien Millerf1ce5052003-06-11 22:04:39 +1000173added support for protocol version 2.