1*0fdf8faeSEd Maste.\" $OpenBSD: ssh-keyscan.1,v 1.52 2024/06/17 08:30:29 djm 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*0fdf8faeSEd Maste.Dd $Mdocdate: June 17 2024 $ 101e8db6e2SBrian Feldman.Dt SSH-KEYSCAN 1 111e8db6e2SBrian Feldman.Os 121e8db6e2SBrian Feldman.Sh NAME 131e8db6e2SBrian Feldman.Nm ssh-keyscan 1419261079SEd Maste.Nd gather SSH public keys from servers 151e8db6e2SBrian Feldman.Sh SYNOPSIS 161e8db6e2SBrian Feldman.Nm ssh-keyscan 17*0fdf8faeSEd Maste.Op Fl 46cDHqv 185e8dbd04SDag-Erling Smørgrav.Op Fl f Ar file 194d3fc8b0SEd Maste.Op Fl O Ar option 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 241e8db6e2SBrian Feldman.Sh DESCRIPTION 251e8db6e2SBrian Feldman.Nm 2647dd1d1bSDag-Erling Smørgravis a utility for gathering the public SSH host keys of a number of 27d0c8c0bcSDag-Erling Smørgravhosts. 28d0c8c0bcSDag-Erling SmørgravIt was designed to aid in building and verifying 291e8db6e2SBrian Feldman.Pa ssh_known_hosts 3047dd1d1bSDag-Erling Smørgravfiles, 3147dd1d1bSDag-Erling Smørgravthe format of which is documented in 3247dd1d1bSDag-Erling Smørgrav.Xr sshd 8 . 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 4247dd1d1bSDag-Erling Smørgravhosts are down or do not run 4347dd1d1bSDag-Erling Smørgrav.Xr sshd 8 . 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 48f374ba41SEd MasteHosts to be scanned may be specified by hostname, address or by CIDR 49f374ba41SEd Mastenetwork range (e.g. 192.168.16/28). 50f374ba41SEd MasteIf a network range is specified, then all addresses in that range will 51f374ba41SEd Mastebe scanned. 52f374ba41SEd Maste.Pp 53ae1f160dSDag-Erling SmørgravThe options are as follows: 541e8db6e2SBrian Feldman.Bl -tag -width Ds 555e8dbd04SDag-Erling Smørgrav.It Fl 4 5647dd1d1bSDag-Erling SmørgravForce 575e8dbd04SDag-Erling Smørgrav.Nm 585e8dbd04SDag-Erling Smørgravto use IPv4 addresses only. 595e8dbd04SDag-Erling Smørgrav.It Fl 6 6047dd1d1bSDag-Erling SmørgravForce 615e8dbd04SDag-Erling Smørgrav.Nm 625e8dbd04SDag-Erling Smørgravto use IPv6 addresses only. 63acc1a9efSDag-Erling Smørgrav.It Fl c 64acc1a9efSDag-Erling SmørgravRequest certificates from target hosts instead of plain keys. 6547dd1d1bSDag-Erling Smørgrav.It Fl D 6647dd1d1bSDag-Erling SmørgravPrint keys found as SSHFP DNS records. 6747dd1d1bSDag-Erling SmørgravThe default is to print keys in a format usable as a 6847dd1d1bSDag-Erling Smørgrav.Xr ssh 1 6947dd1d1bSDag-Erling Smørgrav.Pa known_hosts 7047dd1d1bSDag-Erling Smørgravfile. 715e8dbd04SDag-Erling Smørgrav.It Fl f Ar file 725e8dbd04SDag-Erling SmørgravRead hosts or 73b83788ffSDag-Erling Smørgrav.Dq addrlist namelist 74b83788ffSDag-Erling Smørgravpairs from 75b83788ffSDag-Erling Smørgrav.Ar file , 76b83788ffSDag-Erling Smørgravone per line. 775e8dbd04SDag-Erling SmørgravIf 7847dd1d1bSDag-Erling Smørgrav.Sq - 795e8dbd04SDag-Erling Smørgravis supplied instead of a filename, 805e8dbd04SDag-Erling Smørgrav.Nm 8147dd1d1bSDag-Erling Smørgravwill read from the standard input. 82f374ba41SEd MasteNames read from a file must start with an address, hostname or CIDR network 83f374ba41SEd Masterange to be scanned. 84f374ba41SEd MasteAddresses and hostnames may optionally be followed by comma-separated name 85f374ba41SEd Masteor address aliases that will be copied to the output. 86f374ba41SEd MasteFor example: 8747dd1d1bSDag-Erling Smørgrav.Bd -literal 88f374ba41SEd Maste192.168.11.0/24 89f374ba41SEd Maste10.20.1.1 90f374ba41SEd Mastehappy.example.org 91f374ba41SEd Maste10.0.0.1,sad.example.org 9247dd1d1bSDag-Erling Smørgrav.Ed 935e8dbd04SDag-Erling Smørgrav.It Fl H 945e8dbd04SDag-Erling SmørgravHash all hostnames and addresses in the output. 955e8dbd04SDag-Erling SmørgravHashed names may be used normally by 9647dd1d1bSDag-Erling Smørgrav.Xr ssh 1 975e8dbd04SDag-Erling Smørgravand 9847dd1d1bSDag-Erling Smørgrav.Xr sshd 8 , 995e8dbd04SDag-Erling Smørgravbut they do not reveal identifying information should the file's contents 1005e8dbd04SDag-Erling Smørgravbe disclosed. 1014d3fc8b0SEd Maste.It Fl O Ar option 1024d3fc8b0SEd MasteSpecify a key/value option. 1034d3fc8b0SEd MasteAt present, only a single option is supported: 1044d3fc8b0SEd Maste.Bl -tag -width Ds 1054d3fc8b0SEd Maste.It Cm hashalg Ns = Ns Ar algorithm 1064d3fc8b0SEd MasteSelects a hash algorithm to use when printing SSHFP records using the 1074d3fc8b0SEd Maste.Fl D 1084d3fc8b0SEd Masteflag. 1094d3fc8b0SEd MasteValid algorithms are 1104d3fc8b0SEd Maste.Dq sha1 1114d3fc8b0SEd Masteand 1124d3fc8b0SEd Maste.Dq sha256 . 1134d3fc8b0SEd MasteThe default is to print both. 1144d3fc8b0SEd Maste.El 115ae1f160dSDag-Erling Smørgrav.It Fl p Ar port 11647dd1d1bSDag-Erling SmørgravConnect to 11747dd1d1bSDag-Erling Smørgrav.Ar port 11847dd1d1bSDag-Erling Smørgravon the remote host. 119*0fdf8faeSEd Maste.It Fl q 120*0fdf8faeSEd MasteQuiet mode: 121*0fdf8faeSEd Mastedo not print server host name and banners in comments. 122ae1f160dSDag-Erling Smørgrav.It Fl T Ar timeout 123d0c8c0bcSDag-Erling SmørgravSet the timeout for connection attempts. 124d0c8c0bcSDag-Erling SmørgravIf 125b83788ffSDag-Erling Smørgrav.Ar timeout 1261e8db6e2SBrian Feldmanseconds have elapsed since a connection was initiated to a host or since the 12747dd1d1bSDag-Erling Smørgravlast time anything was read from that host, the connection is 128d0c8c0bcSDag-Erling Smørgravclosed and the host in question considered unavailable. 12947dd1d1bSDag-Erling SmørgravThe default is 5 seconds. 130ae1f160dSDag-Erling Smørgrav.It Fl t Ar type 13147dd1d1bSDag-Erling SmørgravSpecify the type of the key to fetch from the scanned hosts. 132ae1f160dSDag-Erling SmørgravThe possible values are 133f7167e0eSDag-Erling Smørgrav.Dq ecdsa , 134f7167e0eSDag-Erling Smørgrav.Dq ed25519 , 13538a52bd3SEd Maste.Dq ecdsa-sk , 13638a52bd3SEd Maste.Dq ed25519-sk , 137ae1f160dSDag-Erling Smørgravor 1384f52dfbbSDag-Erling Smørgrav.Dq rsa . 139ae1f160dSDag-Erling SmørgravMultiple values may be specified by separating them with commas. 140*0fdf8faeSEd MasteThe default is to fetch all the above key types. 141ae1f160dSDag-Erling Smørgrav.It Fl v 14247dd1d1bSDag-Erling SmørgravVerbose mode: 14347dd1d1bSDag-Erling Smørgravprint debugging messages about progress. 1441e8db6e2SBrian Feldman.El 14547dd1d1bSDag-Erling Smørgrav.Pp 14692eb0aa1SDag-Erling SmørgravIf an ssh_known_hosts file is constructed using 147ae1f160dSDag-Erling Smørgrav.Nm 148ae1f160dSDag-Erling Smørgravwithout verifying the keys, users will be vulnerable to 149d74d50a8SDag-Erling Smørgrav.Em man in the middle 150ae1f160dSDag-Erling Smørgravattacks. 151ae1f160dSDag-Erling SmørgravOn the other hand, if the security model allows such a risk, 152ae1f160dSDag-Erling Smørgrav.Nm 153ae1f160dSDag-Erling Smørgravcan help in the detection of tampered keyfiles or man in the middle 154ae1f160dSDag-Erling Smørgravattacks which have begun after the ssh_known_hosts file was created. 155ae1f160dSDag-Erling Smørgrav.Sh FILES 156ae1f160dSDag-Erling Smørgrav.Pa /etc/ssh/ssh_known_hosts 157d95e11bfSDag-Erling Smørgrav.Sh EXAMPLES 15847dd1d1bSDag-Erling SmørgravPrint the RSA host key for machine 159b83788ffSDag-Erling Smørgrav.Ar hostname : 16047dd1d1bSDag-Erling Smørgrav.Pp 16147dd1d1bSDag-Erling Smørgrav.Dl $ ssh-keyscan -t rsa hostname 162d95e11bfSDag-Erling Smørgrav.Pp 163f374ba41SEd MasteSearch a network range, printing all supported key types: 164f374ba41SEd Maste.Pp 165f374ba41SEd Maste.Dl $ ssh-keyscan 192.168.0.64/25 166f374ba41SEd Maste.Pp 167d95e11bfSDag-Erling SmørgravFind all hosts from the file 168d95e11bfSDag-Erling Smørgrav.Pa ssh_hosts 169d95e11bfSDag-Erling Smørgravwhich have new or different keys from those in the sorted file 170d95e11bfSDag-Erling Smørgrav.Pa ssh_known_hosts : 17147dd1d1bSDag-Erling Smørgrav.Bd -literal -offset indent 172*0fdf8faeSEd Maste$ ssh-keyscan -t rsa,ecdsa,ed25519 -f ssh_hosts | \e 173d95e11bfSDag-Erling Smørgrav sort -u - ssh_known_hosts | diff ssh_known_hosts - 174d95e11bfSDag-Erling Smørgrav.Ed 175d95e11bfSDag-Erling Smørgrav.Sh SEE ALSO 176d95e11bfSDag-Erling Smørgrav.Xr ssh 1 , 177d95e11bfSDag-Erling Smørgrav.Xr sshd 8 17847dd1d1bSDag-Erling Smørgrav.Rs 17947dd1d1bSDag-Erling Smørgrav.%D 2006 18047dd1d1bSDag-Erling Smørgrav.%R RFC 4255 18147dd1d1bSDag-Erling Smørgrav.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints 18247dd1d1bSDag-Erling Smørgrav.Re 183d95e11bfSDag-Erling Smørgrav.Sh AUTHORS 184021d409fSDag-Erling Smørgrav.An -nosplit 185e4a9863fSDag-Erling Smørgrav.An David Mazieres Aq Mt dm@lcs.mit.edu 186d95e11bfSDag-Erling Smørgravwrote the initial version, and 187e4a9863fSDag-Erling Smørgrav.An Wayne Davison Aq Mt wayned@users.sourceforge.net 188d95e11bfSDag-Erling Smørgravadded support for protocol version 2. 189