1*b83788ffSDag-Erling Smørgrav.\" $OpenBSD: ssh-keyscan.1,v 1.34 2014/01/28 14:13:39 jmc Exp $ 2cce7d346SDag-Erling Smørgrav.\" $FreeBSD$ 31e8db6e2SBrian Feldman.\" 41e8db6e2SBrian Feldman.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>. 51e8db6e2SBrian Feldman.\" 61e8db6e2SBrian Feldman.\" Modification and redistribution in source and binary forms is 71e8db6e2SBrian Feldman.\" permitted provided that due credit is given to the author and the 8ae1f160dSDag-Erling Smørgrav.\" OpenBSD project by leaving this copyright notice intact. 91e8db6e2SBrian Feldman.\" 10*b83788ffSDag-Erling Smørgrav.Dd January 28, 2014 111e8db6e2SBrian Feldman.Dt SSH-KEYSCAN 1 121e8db6e2SBrian Feldman.Os 131e8db6e2SBrian Feldman.Sh NAME 141e8db6e2SBrian Feldman.Nm ssh-keyscan 151e8db6e2SBrian Feldman.Nd gather ssh public keys 161e8db6e2SBrian Feldman.Sh SYNOPSIS 171e8db6e2SBrian Feldman.Nm ssh-keyscan 18d0c8c0bcSDag-Erling Smørgrav.Bk -words 195e8dbd04SDag-Erling Smørgrav.Op Fl 46Hv 205e8dbd04SDag-Erling Smørgrav.Op Fl f Ar file 21ae1f160dSDag-Erling Smørgrav.Op Fl p Ar port 22ae1f160dSDag-Erling Smørgrav.Op Fl T Ar timeout 23ae1f160dSDag-Erling Smørgrav.Op Fl t Ar type 24ae1f160dSDag-Erling Smørgrav.Op Ar host | addrlist namelist 25cce7d346SDag-Erling Smørgrav.Ar ... 26d0c8c0bcSDag-Erling Smørgrav.Ek 271e8db6e2SBrian Feldman.Sh DESCRIPTION 281e8db6e2SBrian Feldman.Nm 291e8db6e2SBrian Feldmanis a utility for gathering the public ssh host keys of a number of 30d0c8c0bcSDag-Erling Smørgravhosts. 31d0c8c0bcSDag-Erling SmørgravIt was designed to aid in building and verifying 321e8db6e2SBrian Feldman.Pa ssh_known_hosts 331e8db6e2SBrian Feldmanfiles. 341e8db6e2SBrian Feldman.Nm 351e8db6e2SBrian Feldmanprovides a minimal interface suitable for use by shell and perl 361e8db6e2SBrian Feldmanscripts. 371e8db6e2SBrian Feldman.Pp 381e8db6e2SBrian Feldman.Nm 391e8db6e2SBrian Feldmanuses non-blocking socket I/O to contact as many hosts as possible in 40d0c8c0bcSDag-Erling Smørgravparallel, so it is very efficient. 41d0c8c0bcSDag-Erling SmørgravThe keys from a domain of 1,000 421e8db6e2SBrian Feldmanhosts can be collected in tens of seconds, even when some of those 43d0c8c0bcSDag-Erling Smørgravhosts are down or do not run ssh. 44d0c8c0bcSDag-Erling SmørgravFor scanning, one does not need 45ae1f160dSDag-Erling Smørgravlogin access to the machines that are being scanned, nor does the 46ae1f160dSDag-Erling Smørgravscanning process involve any encryption. 47ae1f160dSDag-Erling Smørgrav.Pp 48ae1f160dSDag-Erling SmørgravThe options are as follows: 491e8db6e2SBrian Feldman.Bl -tag -width Ds 505e8dbd04SDag-Erling Smørgrav.It Fl 4 515e8dbd04SDag-Erling SmørgravForces 525e8dbd04SDag-Erling Smørgrav.Nm 535e8dbd04SDag-Erling Smørgravto use IPv4 addresses only. 545e8dbd04SDag-Erling Smørgrav.It Fl 6 555e8dbd04SDag-Erling SmørgravForces 565e8dbd04SDag-Erling Smørgrav.Nm 575e8dbd04SDag-Erling Smørgravto use IPv6 addresses only. 585e8dbd04SDag-Erling Smørgrav.It Fl f Ar file 595e8dbd04SDag-Erling SmørgravRead hosts or 60*b83788ffSDag-Erling Smørgrav.Dq addrlist namelist 61*b83788ffSDag-Erling Smørgravpairs from 62*b83788ffSDag-Erling Smørgrav.Ar file , 63*b83788ffSDag-Erling Smørgravone per line. 645e8dbd04SDag-Erling SmørgravIf 655e8dbd04SDag-Erling Smørgrav.Pa - 665e8dbd04SDag-Erling Smørgravis supplied instead of a filename, 675e8dbd04SDag-Erling Smørgrav.Nm 685e8dbd04SDag-Erling Smørgravwill read hosts or 69*b83788ffSDag-Erling Smørgrav.Dq addrlist namelist 705e8dbd04SDag-Erling Smørgravpairs from the standard input. 715e8dbd04SDag-Erling Smørgrav.It Fl H 725e8dbd04SDag-Erling SmørgravHash all hostnames and addresses in the output. 735e8dbd04SDag-Erling SmørgravHashed names may be used normally by 745e8dbd04SDag-Erling Smørgrav.Nm ssh 755e8dbd04SDag-Erling Smørgravand 765e8dbd04SDag-Erling Smørgrav.Nm sshd , 775e8dbd04SDag-Erling Smørgravbut they do not reveal identifying information should the file's contents 785e8dbd04SDag-Erling Smørgravbe disclosed. 79ae1f160dSDag-Erling Smørgrav.It Fl p Ar port 80ae1f160dSDag-Erling SmørgravPort to connect to on the remote host. 81ae1f160dSDag-Erling Smørgrav.It Fl T Ar timeout 82d0c8c0bcSDag-Erling SmørgravSet the timeout for connection attempts. 83d0c8c0bcSDag-Erling SmørgravIf 84*b83788ffSDag-Erling Smørgrav.Ar timeout 851e8db6e2SBrian Feldmanseconds have elapsed since a connection was initiated to a host or since the 861e8db6e2SBrian Feldmanlast time anything was read from that host, then the connection is 87d0c8c0bcSDag-Erling Smørgravclosed and the host in question considered unavailable. 88d0c8c0bcSDag-Erling SmørgravDefault is 5 seconds. 89ae1f160dSDag-Erling Smørgrav.It Fl t Ar type 90ae1f160dSDag-Erling SmørgravSpecifies the type of the key to fetch from the scanned hosts. 91ae1f160dSDag-Erling SmørgravThe possible values are 92ae1f160dSDag-Erling Smørgrav.Dq rsa1 93ae1f160dSDag-Erling Smørgravfor protocol version 1 and 944a421b63SDag-Erling Smørgrav.Dq dsa , 95f7167e0eSDag-Erling Smørgrav.Dq ecdsa , 96f7167e0eSDag-Erling Smørgrav.Dq ed25519 , 97ae1f160dSDag-Erling Smørgravor 984a421b63SDag-Erling Smørgrav.Dq rsa 99ae1f160dSDag-Erling Smørgravfor protocol version 2. 100ae1f160dSDag-Erling SmørgravMultiple values may be specified by separating them with commas. 101f2618bb4SXin LIThe default is to fetch 102f2618bb4SXin LI.Dq rsa 103f2618bb4SXin LIand 104f2618bb4SXin LI.Dq ecdsa 105f2618bb4SXin LIkeys. 106ae1f160dSDag-Erling Smørgrav.It Fl v 107ae1f160dSDag-Erling SmørgravVerbose mode. 108ae1f160dSDag-Erling SmørgravCauses 109ae1f160dSDag-Erling Smørgrav.Nm 110ae1f160dSDag-Erling Smørgravto print debugging messages about its progress. 1111e8db6e2SBrian Feldman.El 112ae1f160dSDag-Erling Smørgrav.Sh SECURITY 11392eb0aa1SDag-Erling SmørgravIf an ssh_known_hosts file is constructed using 114ae1f160dSDag-Erling Smørgrav.Nm 115ae1f160dSDag-Erling Smørgravwithout verifying the keys, users will be vulnerable to 116d74d50a8SDag-Erling Smørgrav.Em man in the middle 117ae1f160dSDag-Erling Smørgravattacks. 118ae1f160dSDag-Erling SmørgravOn the other hand, if the security model allows such a risk, 119ae1f160dSDag-Erling Smørgrav.Nm 120ae1f160dSDag-Erling Smørgravcan help in the detection of tampered keyfiles or man in the middle 121ae1f160dSDag-Erling Smørgravattacks which have begun after the ssh_known_hosts file was created. 122ae1f160dSDag-Erling Smørgrav.Sh FILES 123*b83788ffSDag-Erling SmørgravInput format: 124ae1f160dSDag-Erling Smørgrav.Bd -literal 125ae1f160dSDag-Erling Smørgrav1.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4 1261e8db6e2SBrian Feldman.Ed 1271e8db6e2SBrian Feldman.Pp 128*b83788ffSDag-Erling SmørgravOutput format for rsa1 keys: 129ae1f160dSDag-Erling Smørgrav.Bd -literal 1301e8db6e2SBrian Feldmanhost-or-namelist bits exponent modulus 131ae1f160dSDag-Erling Smørgrav.Ed 1321e8db6e2SBrian Feldman.Pp 133*b83788ffSDag-Erling SmørgravOutput format for rsa, dsa and ecdsa keys: 134ae1f160dSDag-Erling Smørgrav.Bd -literal 135ae1f160dSDag-Erling Smørgravhost-or-namelist keytype base64-encoded-key 136ae1f160dSDag-Erling Smørgrav.Ed 137ae1f160dSDag-Erling Smørgrav.Pp 138ae1f160dSDag-Erling SmørgravWhere 139*b83788ffSDag-Erling Smørgrav.Ar keytype 140ae1f160dSDag-Erling Smørgravis either 1414a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp256 , 1424a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp384 , 1434a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp521 , 144f7167e0eSDag-Erling Smørgrav.Dq ssh-ed25519 , 1454a421b63SDag-Erling Smørgrav.Dq ssh-dss 146ae1f160dSDag-Erling Smørgravor 1474a421b63SDag-Erling Smørgrav.Dq ssh-rsa . 148ae1f160dSDag-Erling Smørgrav.Pp 149ae1f160dSDag-Erling Smørgrav.Pa /etc/ssh/ssh_known_hosts 150d95e11bfSDag-Erling Smørgrav.Sh EXAMPLES 151*b83788ffSDag-Erling SmørgravPrint the rsa host key for machine 152*b83788ffSDag-Erling Smørgrav.Ar hostname : 153d95e11bfSDag-Erling Smørgrav.Bd -literal 154d95e11bfSDag-Erling Smørgrav$ ssh-keyscan hostname 155d95e11bfSDag-Erling Smørgrav.Ed 156d95e11bfSDag-Erling Smørgrav.Pp 157d95e11bfSDag-Erling SmørgravFind all hosts from the file 158d95e11bfSDag-Erling Smørgrav.Pa ssh_hosts 159d95e11bfSDag-Erling Smørgravwhich have new or different keys from those in the sorted file 160d95e11bfSDag-Erling Smørgrav.Pa ssh_known_hosts : 161d95e11bfSDag-Erling Smørgrav.Bd -literal 1624a421b63SDag-Erling Smørgrav$ ssh-keyscan -t rsa,dsa,ecdsa -f ssh_hosts | \e 163d95e11bfSDag-Erling Smørgrav sort -u - ssh_known_hosts | diff ssh_known_hosts - 164d95e11bfSDag-Erling Smørgrav.Ed 165d95e11bfSDag-Erling Smørgrav.Sh SEE ALSO 166d95e11bfSDag-Erling Smørgrav.Xr ssh 1 , 167d95e11bfSDag-Erling Smørgrav.Xr sshd 8 168d95e11bfSDag-Erling Smørgrav.Sh AUTHORS 169021d409fSDag-Erling Smørgrav.An -nosplit 170e4a9863fSDag-Erling Smørgrav.An David Mazieres Aq Mt dm@lcs.mit.edu 171d95e11bfSDag-Erling Smørgravwrote the initial version, and 172e4a9863fSDag-Erling Smørgrav.An Wayne Davison Aq Mt wayned@users.sourceforge.net 173d95e11bfSDag-Erling Smørgravadded support for protocol version 2. 1741e8db6e2SBrian Feldman.Sh BUGS 1751e8db6e2SBrian FeldmanIt generates "Connection closed by remote host" messages on the consoles 176ae1f160dSDag-Erling Smørgravof all the machines it scans if the server is older than version 2.9. 1771e8db6e2SBrian FeldmanThis is because it opens a connection to the ssh port, reads the public 1781e8db6e2SBrian Feldmankey, and drops the connection as soon as it gets the key. 179