1*4f52dfbbSDag-Erling Smørgrav.\" $OpenBSD: ssh-keyscan.1,v 1.40 2017/05/02 17:04:09 jmc Exp $ 21e8db6e2SBrian Feldman.\" 31e8db6e2SBrian Feldman.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>. 41e8db6e2SBrian Feldman.\" 51e8db6e2SBrian Feldman.\" Modification and redistribution in source and binary forms is 61e8db6e2SBrian Feldman.\" permitted provided that due credit is given to the author and the 7ae1f160dSDag-Erling Smørgrav.\" OpenBSD project by leaving this copyright notice intact. 81e8db6e2SBrian Feldman.\" 9*4f52dfbbSDag-Erling Smørgrav.Dd $Mdocdate: May 2 2017 $ 101e8db6e2SBrian Feldman.Dt SSH-KEYSCAN 1 111e8db6e2SBrian Feldman.Os 121e8db6e2SBrian Feldman.Sh NAME 131e8db6e2SBrian Feldman.Nm ssh-keyscan 141e8db6e2SBrian Feldman.Nd gather ssh public keys 151e8db6e2SBrian Feldman.Sh SYNOPSIS 161e8db6e2SBrian Feldman.Nm ssh-keyscan 17d0c8c0bcSDag-Erling Smørgrav.Bk -words 18acc1a9efSDag-Erling Smørgrav.Op Fl 46cHv 195e8dbd04SDag-Erling Smørgrav.Op Fl f Ar file 20ae1f160dSDag-Erling Smørgrav.Op Fl p Ar port 21ae1f160dSDag-Erling Smørgrav.Op Fl T Ar timeout 22ae1f160dSDag-Erling Smørgrav.Op Fl t Ar type 23ae1f160dSDag-Erling Smørgrav.Op Ar host | addrlist namelist 24cce7d346SDag-Erling Smørgrav.Ar ... 25d0c8c0bcSDag-Erling Smørgrav.Ek 261e8db6e2SBrian Feldman.Sh DESCRIPTION 271e8db6e2SBrian Feldman.Nm 281e8db6e2SBrian Feldmanis a utility for gathering the public ssh host keys of a number of 29d0c8c0bcSDag-Erling Smørgravhosts. 30d0c8c0bcSDag-Erling SmørgravIt was designed to aid in building and verifying 311e8db6e2SBrian Feldman.Pa ssh_known_hosts 321e8db6e2SBrian Feldmanfiles. 331e8db6e2SBrian Feldman.Nm 341e8db6e2SBrian Feldmanprovides a minimal interface suitable for use by shell and perl 351e8db6e2SBrian Feldmanscripts. 361e8db6e2SBrian Feldman.Pp 371e8db6e2SBrian Feldman.Nm 381e8db6e2SBrian Feldmanuses non-blocking socket I/O to contact as many hosts as possible in 39d0c8c0bcSDag-Erling Smørgravparallel, so it is very efficient. 40d0c8c0bcSDag-Erling SmørgravThe keys from a domain of 1,000 411e8db6e2SBrian Feldmanhosts can be collected in tens of seconds, even when some of those 42d0c8c0bcSDag-Erling Smørgravhosts are down or do not run ssh. 43d0c8c0bcSDag-Erling SmørgravFor scanning, one does not need 44ae1f160dSDag-Erling Smørgravlogin access to the machines that are being scanned, nor does the 45ae1f160dSDag-Erling Smørgravscanning process involve any encryption. 46ae1f160dSDag-Erling Smørgrav.Pp 47ae1f160dSDag-Erling SmørgravThe options are as follows: 481e8db6e2SBrian Feldman.Bl -tag -width Ds 495e8dbd04SDag-Erling Smørgrav.It Fl 4 505e8dbd04SDag-Erling SmørgravForces 515e8dbd04SDag-Erling Smørgrav.Nm 525e8dbd04SDag-Erling Smørgravto use IPv4 addresses only. 535e8dbd04SDag-Erling Smørgrav.It Fl 6 545e8dbd04SDag-Erling SmørgravForces 555e8dbd04SDag-Erling Smørgrav.Nm 565e8dbd04SDag-Erling Smørgravto use IPv6 addresses only. 57acc1a9efSDag-Erling Smørgrav.It Fl c 58acc1a9efSDag-Erling SmørgravRequest certificates from target hosts instead of plain keys. 595e8dbd04SDag-Erling Smørgrav.It Fl f Ar file 605e8dbd04SDag-Erling SmørgravRead hosts or 61b83788ffSDag-Erling Smørgrav.Dq addrlist namelist 62b83788ffSDag-Erling Smørgravpairs from 63b83788ffSDag-Erling Smørgrav.Ar file , 64b83788ffSDag-Erling Smørgravone per line. 655e8dbd04SDag-Erling SmørgravIf 665e8dbd04SDag-Erling Smørgrav.Pa - 675e8dbd04SDag-Erling Smørgravis supplied instead of a filename, 685e8dbd04SDag-Erling Smørgrav.Nm 695e8dbd04SDag-Erling Smørgravwill read hosts or 70b83788ffSDag-Erling Smørgrav.Dq addrlist namelist 715e8dbd04SDag-Erling Smørgravpairs from the standard input. 725e8dbd04SDag-Erling Smørgrav.It Fl H 735e8dbd04SDag-Erling SmørgravHash all hostnames and addresses in the output. 745e8dbd04SDag-Erling SmørgravHashed names may be used normally by 755e8dbd04SDag-Erling Smørgrav.Nm ssh 765e8dbd04SDag-Erling Smørgravand 775e8dbd04SDag-Erling Smørgrav.Nm sshd , 785e8dbd04SDag-Erling Smørgravbut they do not reveal identifying information should the file's contents 795e8dbd04SDag-Erling Smørgravbe disclosed. 80ae1f160dSDag-Erling Smørgrav.It Fl p Ar port 81ae1f160dSDag-Erling SmørgravPort to connect to on the remote host. 82ae1f160dSDag-Erling Smørgrav.It Fl T Ar timeout 83d0c8c0bcSDag-Erling SmørgravSet the timeout for connection attempts. 84d0c8c0bcSDag-Erling SmørgravIf 85b83788ffSDag-Erling Smørgrav.Ar timeout 861e8db6e2SBrian Feldmanseconds have elapsed since a connection was initiated to a host or since the 871e8db6e2SBrian Feldmanlast time anything was read from that host, then the connection is 88d0c8c0bcSDag-Erling Smørgravclosed and the host in question considered unavailable. 89d0c8c0bcSDag-Erling SmørgravDefault is 5 seconds. 90ae1f160dSDag-Erling Smørgrav.It Fl t Ar type 91ae1f160dSDag-Erling SmørgravSpecifies the type of the key to fetch from the scanned hosts. 92ae1f160dSDag-Erling SmørgravThe possible values are 934a421b63SDag-Erling Smørgrav.Dq dsa , 94f7167e0eSDag-Erling Smørgrav.Dq ecdsa , 95f7167e0eSDag-Erling Smørgrav.Dq ed25519 , 96ae1f160dSDag-Erling Smørgravor 97*4f52dfbbSDag-Erling Smørgrav.Dq rsa . 98ae1f160dSDag-Erling SmørgravMultiple values may be specified by separating them with commas. 99f2618bb4SXin LIThe default is to fetch 100a0ee8cc6SDag-Erling Smørgrav.Dq rsa , 101a0ee8cc6SDag-Erling Smørgrav.Dq ecdsa , 102f2618bb4SXin LIand 103a0ee8cc6SDag-Erling Smørgrav.Dq ed25519 104f2618bb4SXin LIkeys. 105ae1f160dSDag-Erling Smørgrav.It Fl v 106ae1f160dSDag-Erling SmørgravVerbose mode. 107ae1f160dSDag-Erling SmørgravCauses 108ae1f160dSDag-Erling Smørgrav.Nm 109ae1f160dSDag-Erling Smørgravto print debugging messages about its progress. 1101e8db6e2SBrian Feldman.El 111ae1f160dSDag-Erling Smørgrav.Sh SECURITY 11292eb0aa1SDag-Erling SmørgravIf an ssh_known_hosts file is constructed using 113ae1f160dSDag-Erling Smørgrav.Nm 114ae1f160dSDag-Erling Smørgravwithout verifying the keys, users will be vulnerable to 115d74d50a8SDag-Erling Smørgrav.Em man in the middle 116ae1f160dSDag-Erling Smørgravattacks. 117ae1f160dSDag-Erling SmørgravOn the other hand, if the security model allows such a risk, 118ae1f160dSDag-Erling Smørgrav.Nm 119ae1f160dSDag-Erling Smørgravcan help in the detection of tampered keyfiles or man in the middle 120ae1f160dSDag-Erling Smørgravattacks which have begun after the ssh_known_hosts file was created. 121ae1f160dSDag-Erling Smørgrav.Sh FILES 122b83788ffSDag-Erling SmørgravInput format: 123ae1f160dSDag-Erling Smørgrav.Bd -literal 124ae1f160dSDag-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 1251e8db6e2SBrian Feldman.Ed 1261e8db6e2SBrian Feldman.Pp 127bc5531deSDag-Erling SmørgravOutput format for RSA, DSA, ECDSA, and Ed25519 keys: 128ae1f160dSDag-Erling Smørgrav.Bd -literal 129ae1f160dSDag-Erling Smørgravhost-or-namelist keytype base64-encoded-key 130ae1f160dSDag-Erling Smørgrav.Ed 131ae1f160dSDag-Erling Smørgrav.Pp 132ae1f160dSDag-Erling SmørgravWhere 133b83788ffSDag-Erling Smørgrav.Ar keytype 134ae1f160dSDag-Erling Smørgravis either 1354a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp256 , 1364a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp384 , 1374a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp521 , 138f7167e0eSDag-Erling Smørgrav.Dq ssh-ed25519 , 1394a421b63SDag-Erling Smørgrav.Dq ssh-dss 140ae1f160dSDag-Erling Smørgravor 1414a421b63SDag-Erling Smørgrav.Dq ssh-rsa . 142ae1f160dSDag-Erling Smørgrav.Pp 143ae1f160dSDag-Erling Smørgrav.Pa /etc/ssh/ssh_known_hosts 144d95e11bfSDag-Erling Smørgrav.Sh EXAMPLES 145b83788ffSDag-Erling SmørgravPrint the rsa host key for machine 146b83788ffSDag-Erling Smørgrav.Ar hostname : 147d95e11bfSDag-Erling Smørgrav.Bd -literal 148d95e11bfSDag-Erling Smørgrav$ ssh-keyscan hostname 149d95e11bfSDag-Erling Smørgrav.Ed 150d95e11bfSDag-Erling Smørgrav.Pp 151d95e11bfSDag-Erling SmørgravFind all hosts from the file 152d95e11bfSDag-Erling Smørgrav.Pa ssh_hosts 153d95e11bfSDag-Erling Smørgravwhich have new or different keys from those in the sorted file 154d95e11bfSDag-Erling Smørgrav.Pa ssh_known_hosts : 155d95e11bfSDag-Erling Smørgrav.Bd -literal 156a0ee8cc6SDag-Erling Smørgrav$ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e 157d95e11bfSDag-Erling Smørgrav sort -u - ssh_known_hosts | diff ssh_known_hosts - 158d95e11bfSDag-Erling Smørgrav.Ed 159d95e11bfSDag-Erling Smørgrav.Sh SEE ALSO 160d95e11bfSDag-Erling Smørgrav.Xr ssh 1 , 161d95e11bfSDag-Erling Smørgrav.Xr sshd 8 162d95e11bfSDag-Erling Smørgrav.Sh AUTHORS 163021d409fSDag-Erling Smørgrav.An -nosplit 164e4a9863fSDag-Erling Smørgrav.An David Mazieres Aq Mt dm@lcs.mit.edu 165d95e11bfSDag-Erling Smørgravwrote the initial version, and 166e4a9863fSDag-Erling Smørgrav.An Wayne Davison Aq Mt wayned@users.sourceforge.net 167d95e11bfSDag-Erling Smørgravadded support for protocol version 2. 1681e8db6e2SBrian Feldman.Sh BUGS 1691e8db6e2SBrian FeldmanIt generates "Connection closed by remote host" messages on the consoles 170ae1f160dSDag-Erling Smørgravof all the machines it scans if the server is older than version 2.9. 1711e8db6e2SBrian FeldmanThis is because it opens a connection to the ssh port, reads the public 1721e8db6e2SBrian Feldmankey, and drops the connection as soon as it gets the key. 173