1.\" $NetBSD: ssh-keyscan.1,v 1.16 2020/02/27 00:24:40 christos Exp $ 2.\" $OpenBSD: ssh-keyscan.1,v 1.45 2019/11/30 07:07:59 jmc 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 November 30 2019 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 , 107or 108.Dq rsa . 109Multiple values may be specified by separating them with commas. 110The default is to fetch 111.Dq rsa , 112.Dq ecdsa , 113and 114.Dq ed25519 115keys. 116.It Fl v 117Verbose mode: 118print debugging messages about progress. 119.El 120.Pp 121If an ssh_known_hosts file is constructed using 122.Nm 123without verifying the keys, users will be vulnerable to 124.Em man in the middle 125attacks. 126On the other hand, if the security model allows such a risk, 127.Nm 128can help in the detection of tampered keyfiles or man in the middle 129attacks which have begun after the ssh_known_hosts file was created. 130.Sh FILES 131.Pa /etc/ssh/ssh_known_hosts 132.Sh EXAMPLES 133Print the RSA host key for machine 134.Ar hostname : 135.Pp 136.Dl $ ssh-keyscan -t rsa hostname 137.Pp 138Find all hosts from the file 139.Pa ssh_hosts 140which have new or different keys from those in the sorted file 141.Pa ssh_known_hosts : 142.Bd -literal -offset indent 143$ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e 144 sort -u - ssh_known_hosts | diff ssh_known_hosts - 145.Ed 146.Sh SEE ALSO 147.Xr ssh 1 , 148.Xr sshd 8 149.Rs 150.%D 2006 151.%R RFC 4255 152.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints 153.Re 154.Sh AUTHORS 155.An -nosplit 156.An David Mazieres Aq Mt dm@lcs.mit.edu 157wrote the initial version, and 158.An Wayne Davison Aq Mt wayned@users.sourceforge.net 159added support for protocol version 2. 160