1.\" $OpenBSD: ssh-keyscan.1,v 1.34 2014/01/28 14:13:39 jmc Exp $ 2.\" $FreeBSD$ 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 January 28, 2014 11.Dt SSH-KEYSCAN 1 12.Os 13.Sh NAME 14.Nm ssh-keyscan 15.Nd gather ssh public keys 16.Sh SYNOPSIS 17.Nm ssh-keyscan 18.Bk -words 19.Op Fl 46Hv 20.Op Fl f Ar file 21.Op Fl p Ar port 22.Op Fl T Ar timeout 23.Op Fl t Ar type 24.Op Ar host | addrlist namelist 25.Ar ... 26.Ek 27.Sh DESCRIPTION 28.Nm 29is a utility for gathering the public ssh host keys of a number of 30hosts. 31It was designed to aid in building and verifying 32.Pa ssh_known_hosts 33files. 34.Nm 35provides a minimal interface suitable for use by shell and perl 36scripts. 37.Pp 38.Nm 39uses non-blocking socket I/O to contact as many hosts as possible in 40parallel, so it is very efficient. 41The keys from a domain of 1,000 42hosts can be collected in tens of seconds, even when some of those 43hosts are down or do not run ssh. 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 51Forces 52.Nm 53to use IPv4 addresses only. 54.It Fl 6 55Forces 56.Nm 57to use IPv6 addresses only. 58.It Fl f Ar file 59Read hosts or 60.Dq addrlist namelist 61pairs from 62.Ar file , 63one per line. 64If 65.Pa - 66is supplied instead of a filename, 67.Nm 68will read hosts or 69.Dq addrlist namelist 70pairs from the standard input. 71.It Fl H 72Hash all hostnames and addresses in the output. 73Hashed names may be used normally by 74.Nm ssh 75and 76.Nm sshd , 77but they do not reveal identifying information should the file's contents 78be disclosed. 79.It Fl p Ar port 80Port to connect to on the remote host. 81.It Fl T Ar timeout 82Set the timeout for connection attempts. 83If 84.Ar timeout 85seconds have elapsed since a connection was initiated to a host or since the 86last time anything was read from that host, then the connection is 87closed and the host in question considered unavailable. 88Default is 5 seconds. 89.It Fl t Ar type 90Specifies the type of the key to fetch from the scanned hosts. 91The possible values are 92.Dq rsa1 93for protocol version 1 and 94.Dq dsa , 95.Dq ecdsa , 96.Dq ed25519 , 97or 98.Dq rsa 99for protocol version 2. 100Multiple values may be specified by separating them with commas. 101The default is to fetch 102.Dq rsa 103and 104.Dq ecdsa 105keys. 106.It Fl v 107Verbose mode. 108Causes 109.Nm 110to print debugging messages about its progress. 111.El 112.Sh SECURITY 113If an ssh_known_hosts file is constructed using 114.Nm 115without verifying the keys, users will be vulnerable to 116.Em man in the middle 117attacks. 118On the other hand, if the security model allows such a risk, 119.Nm 120can help in the detection of tampered keyfiles or man in the middle 121attacks which have begun after the ssh_known_hosts file was created. 122.Sh FILES 123Input format: 124.Bd -literal 1251.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4 126.Ed 127.Pp 128Output format for rsa1 keys: 129.Bd -literal 130host-or-namelist bits exponent modulus 131.Ed 132.Pp 133Output format for rsa, dsa and ecdsa keys: 134.Bd -literal 135host-or-namelist keytype base64-encoded-key 136.Ed 137.Pp 138Where 139.Ar keytype 140is either 141.Dq ecdsa-sha2-nistp256 , 142.Dq ecdsa-sha2-nistp384 , 143.Dq ecdsa-sha2-nistp521 , 144.Dq ssh-ed25519 , 145.Dq ssh-dss 146or 147.Dq ssh-rsa . 148.Pp 149.Pa /etc/ssh/ssh_known_hosts 150.Sh EXAMPLES 151Print the rsa host key for machine 152.Ar hostname : 153.Bd -literal 154$ ssh-keyscan hostname 155.Ed 156.Pp 157Find all hosts from the file 158.Pa ssh_hosts 159which have new or different keys from those in the sorted file 160.Pa ssh_known_hosts : 161.Bd -literal 162$ ssh-keyscan -t rsa,dsa,ecdsa -f ssh_hosts | \e 163 sort -u - ssh_known_hosts | diff ssh_known_hosts - 164.Ed 165.Sh SEE ALSO 166.Xr ssh 1 , 167.Xr sshd 8 168.Sh AUTHORS 169.An -nosplit 170.An David Mazieres Aq Mt dm@lcs.mit.edu 171wrote the initial version, and 172.An Wayne Davison Aq Mt wayned@users.sourceforge.net 173added support for protocol version 2. 174.Sh BUGS 175It generates "Connection closed by remote host" messages on the consoles 176of all the machines it scans if the server is older than version 2.9. 177This is because it opens a connection to the ssh port, reads the public 178key, and drops the connection as soon as it gets the key. 179