1*e4a9863fSDag-Erling Smørgrav.\" $OpenBSD: ssh-keyscan.1,v 1.31 2013/07/16 00:07:52 schwarze 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*e4a9863fSDag-Erling Smørgrav.Dd July 16, 2013 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 605e8dbd04SDag-Erling Smørgrav.Pa addrlist namelist 615e8dbd04SDag-Erling Smørgravpairs from this file, one per line. 625e8dbd04SDag-Erling SmørgravIf 635e8dbd04SDag-Erling Smørgrav.Pa - 645e8dbd04SDag-Erling Smørgravis supplied instead of a filename, 655e8dbd04SDag-Erling Smørgrav.Nm 665e8dbd04SDag-Erling Smørgravwill read hosts or 675e8dbd04SDag-Erling Smørgrav.Pa addrlist namelist 685e8dbd04SDag-Erling Smørgravpairs from the standard input. 695e8dbd04SDag-Erling Smørgrav.It Fl H 705e8dbd04SDag-Erling SmørgravHash all hostnames and addresses in the output. 715e8dbd04SDag-Erling SmørgravHashed names may be used normally by 725e8dbd04SDag-Erling Smørgrav.Nm ssh 735e8dbd04SDag-Erling Smørgravand 745e8dbd04SDag-Erling Smørgrav.Nm sshd , 755e8dbd04SDag-Erling Smørgravbut they do not reveal identifying information should the file's contents 765e8dbd04SDag-Erling Smørgravbe disclosed. 77ae1f160dSDag-Erling Smørgrav.It Fl p Ar port 78ae1f160dSDag-Erling SmørgravPort to connect to on the remote host. 79ae1f160dSDag-Erling Smørgrav.It Fl T Ar timeout 80d0c8c0bcSDag-Erling SmørgravSet the timeout for connection attempts. 81d0c8c0bcSDag-Erling SmørgravIf 821e8db6e2SBrian Feldman.Pa timeout 831e8db6e2SBrian Feldmanseconds have elapsed since a connection was initiated to a host or since the 841e8db6e2SBrian Feldmanlast time anything was read from that host, then the connection is 85d0c8c0bcSDag-Erling Smørgravclosed and the host in question considered unavailable. 86d0c8c0bcSDag-Erling SmørgravDefault is 5 seconds. 87ae1f160dSDag-Erling Smørgrav.It Fl t Ar type 88ae1f160dSDag-Erling SmørgravSpecifies the type of the key to fetch from the scanned hosts. 89ae1f160dSDag-Erling SmørgravThe possible values are 90ae1f160dSDag-Erling Smørgrav.Dq rsa1 91ae1f160dSDag-Erling Smørgravfor protocol version 1 and 924a421b63SDag-Erling Smørgrav.Dq dsa , 934a421b63SDag-Erling Smørgrav.Dq ecdsa 94ae1f160dSDag-Erling Smørgravor 954a421b63SDag-Erling Smørgrav.Dq rsa 96ae1f160dSDag-Erling Smørgravfor protocol version 2. 97ae1f160dSDag-Erling SmørgravMultiple values may be specified by separating them with commas. 98f2618bb4SXin LIThe default is to fetch 99f2618bb4SXin LI.Dq rsa 100f2618bb4SXin LIand 101f2618bb4SXin LI.Dq ecdsa 102f2618bb4SXin LIkeys. 103ae1f160dSDag-Erling Smørgrav.It Fl v 104ae1f160dSDag-Erling SmørgravVerbose mode. 105ae1f160dSDag-Erling SmørgravCauses 106ae1f160dSDag-Erling Smørgrav.Nm 107ae1f160dSDag-Erling Smørgravto print debugging messages about its progress. 1081e8db6e2SBrian Feldman.El 109ae1f160dSDag-Erling Smørgrav.Sh SECURITY 11092eb0aa1SDag-Erling SmørgravIf an ssh_known_hosts file is constructed using 111ae1f160dSDag-Erling Smørgrav.Nm 112ae1f160dSDag-Erling Smørgravwithout verifying the keys, users will be vulnerable to 113d74d50a8SDag-Erling Smørgrav.Em man in the middle 114ae1f160dSDag-Erling Smørgravattacks. 115ae1f160dSDag-Erling SmørgravOn the other hand, if the security model allows such a risk, 116ae1f160dSDag-Erling Smørgrav.Nm 117ae1f160dSDag-Erling Smørgravcan help in the detection of tampered keyfiles or man in the middle 118ae1f160dSDag-Erling Smørgravattacks which have begun after the ssh_known_hosts file was created. 119ae1f160dSDag-Erling Smørgrav.Sh FILES 120ae1f160dSDag-Erling Smørgrav.Pa Input format: 121ae1f160dSDag-Erling Smørgrav.Bd -literal 122ae1f160dSDag-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 1231e8db6e2SBrian Feldman.Ed 1241e8db6e2SBrian Feldman.Pp 125ae1f160dSDag-Erling Smørgrav.Pa Output format for rsa1 keys: 126ae1f160dSDag-Erling Smørgrav.Bd -literal 1271e8db6e2SBrian Feldmanhost-or-namelist bits exponent modulus 128ae1f160dSDag-Erling Smørgrav.Ed 1291e8db6e2SBrian Feldman.Pp 1304a421b63SDag-Erling Smørgrav.Pa Output format for rsa, dsa and ecdsa keys: 131ae1f160dSDag-Erling Smørgrav.Bd -literal 132ae1f160dSDag-Erling Smørgravhost-or-namelist keytype base64-encoded-key 133ae1f160dSDag-Erling Smørgrav.Ed 134ae1f160dSDag-Erling Smørgrav.Pp 135ae1f160dSDag-Erling SmørgravWhere 136ae1f160dSDag-Erling Smørgrav.Pa keytype 137ae1f160dSDag-Erling Smørgravis either 1384a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp256 , 1394a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp384 , 1404a421b63SDag-Erling Smørgrav.Dq ecdsa-sha2-nistp521 , 1414a421b63SDag-Erling Smørgrav.Dq ssh-dss 142ae1f160dSDag-Erling Smørgravor 1434a421b63SDag-Erling Smørgrav.Dq ssh-rsa . 144ae1f160dSDag-Erling Smørgrav.Pp 145ae1f160dSDag-Erling Smørgrav.Pa /etc/ssh/ssh_known_hosts 146d95e11bfSDag-Erling Smørgrav.Sh EXAMPLES 147d95e11bfSDag-Erling SmørgravPrint the 148cce7d346SDag-Erling Smørgrav.Pa rsa 149d95e11bfSDag-Erling Smørgravhost key for machine 150d95e11bfSDag-Erling Smørgrav.Pa hostname : 151d95e11bfSDag-Erling Smørgrav.Bd -literal 152d95e11bfSDag-Erling Smørgrav$ ssh-keyscan hostname 153d95e11bfSDag-Erling Smørgrav.Ed 154d95e11bfSDag-Erling Smørgrav.Pp 155d95e11bfSDag-Erling SmørgravFind all hosts from the file 156d95e11bfSDag-Erling Smørgrav.Pa ssh_hosts 157d95e11bfSDag-Erling Smørgravwhich have new or different keys from those in the sorted file 158d95e11bfSDag-Erling Smørgrav.Pa ssh_known_hosts : 159d95e11bfSDag-Erling Smørgrav.Bd -literal 1604a421b63SDag-Erling Smørgrav$ ssh-keyscan -t rsa,dsa,ecdsa -f ssh_hosts | \e 161d95e11bfSDag-Erling Smørgrav sort -u - ssh_known_hosts | diff ssh_known_hosts - 162d95e11bfSDag-Erling Smørgrav.Ed 163d95e11bfSDag-Erling Smørgrav.Sh SEE ALSO 164d95e11bfSDag-Erling Smørgrav.Xr ssh 1 , 165d95e11bfSDag-Erling Smørgrav.Xr sshd 8 166d95e11bfSDag-Erling Smørgrav.Sh AUTHORS 167021d409fSDag-Erling Smørgrav.An -nosplit 168*e4a9863fSDag-Erling Smørgrav.An David Mazieres Aq Mt dm@lcs.mit.edu 169d95e11bfSDag-Erling Smørgravwrote the initial version, and 170*e4a9863fSDag-Erling Smørgrav.An Wayne Davison Aq Mt wayned@users.sourceforge.net 171d95e11bfSDag-Erling Smørgravadded support for protocol version 2. 1721e8db6e2SBrian Feldman.Sh BUGS 1731e8db6e2SBrian FeldmanIt generates "Connection closed by remote host" messages on the consoles 174ae1f160dSDag-Erling Smørgravof all the machines it scans if the server is older than version 2.9. 1751e8db6e2SBrian FeldmanThis is because it opens a connection to the ssh port, reads the public 1761e8db6e2SBrian Feldmankey, and drops the connection as soon as it gets the key. 177