1*ba1276acSMatthew Dillon.\" $OpenBSD: ssh-keyscan.1,v 1.52 2024/06/17 08:30:29 djm Exp $ 218de8d7fSPeter Avalos.\" 318de8d7fSPeter Avalos.\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>. 418de8d7fSPeter Avalos.\" 518de8d7fSPeter Avalos.\" Modification and redistribution in source and binary forms is 618de8d7fSPeter Avalos.\" permitted provided that due credit is given to the author and the 718de8d7fSPeter Avalos.\" OpenBSD project by leaving this copyright notice intact. 818de8d7fSPeter Avalos.\" 9*ba1276acSMatthew Dillon.Dd $Mdocdate: June 17 2024 $ 1018de8d7fSPeter Avalos.Dt SSH-KEYSCAN 1 1118de8d7fSPeter Avalos.Os 1218de8d7fSPeter Avalos.Sh NAME 1318de8d7fSPeter Avalos.Nm ssh-keyscan 140cbfa66cSDaniel Fojt.Nd gather SSH public keys from servers 1518de8d7fSPeter Avalos.Sh SYNOPSIS 1618de8d7fSPeter Avalos.Nm ssh-keyscan 17*ba1276acSMatthew Dillon.Op Fl 46cDHqv 1818de8d7fSPeter Avalos.Op Fl f Ar file 19*ba1276acSMatthew Dillon.Op Fl O Ar option 2018de8d7fSPeter Avalos.Op Fl p Ar port 2118de8d7fSPeter Avalos.Op Fl T Ar timeout 2218de8d7fSPeter Avalos.Op Fl t Ar type 2318de8d7fSPeter Avalos.Op Ar host | addrlist namelist 2418de8d7fSPeter Avalos.Sh DESCRIPTION 2518de8d7fSPeter Avalos.Nm 26664f4763Szrjis a utility for gathering the public SSH host keys of a number of 2718de8d7fSPeter Avaloshosts. 2818de8d7fSPeter AvalosIt was designed to aid in building and verifying 2918de8d7fSPeter Avalos.Pa ssh_known_hosts 30664f4763Szrjfiles, 31664f4763Szrjthe format of which is documented in 32664f4763Szrj.Xr sshd 8 . 3318de8d7fSPeter Avalos.Nm 3418de8d7fSPeter Avalosprovides a minimal interface suitable for use by shell and perl 3518de8d7fSPeter Avalosscripts. 3618de8d7fSPeter Avalos.Pp 3718de8d7fSPeter Avalos.Nm 3818de8d7fSPeter Avalosuses non-blocking socket I/O to contact as many hosts as possible in 3918de8d7fSPeter Avalosparallel, so it is very efficient. 4018de8d7fSPeter AvalosThe keys from a domain of 1,000 4118de8d7fSPeter Avaloshosts can be collected in tens of seconds, even when some of those 42664f4763Szrjhosts are down or do not run 43664f4763Szrj.Xr sshd 8 . 4418de8d7fSPeter AvalosFor scanning, one does not need 4518de8d7fSPeter Avaloslogin access to the machines that are being scanned, nor does the 4618de8d7fSPeter Avalosscanning process involve any encryption. 4718de8d7fSPeter Avalos.Pp 48*ba1276acSMatthew DillonHosts to be scanned may be specified by hostname, address or by CIDR 49*ba1276acSMatthew Dillonnetwork range (e.g. 192.168.16/28). 50*ba1276acSMatthew DillonIf a network range is specified, then all addresses in that range will 51*ba1276acSMatthew Dillonbe scanned. 52*ba1276acSMatthew Dillon.Pp 5318de8d7fSPeter AvalosThe options are as follows: 5418de8d7fSPeter Avalos.Bl -tag -width Ds 5518de8d7fSPeter Avalos.It Fl 4 56664f4763SzrjForce 5718de8d7fSPeter Avalos.Nm 5818de8d7fSPeter Avalosto use IPv4 addresses only. 5918de8d7fSPeter Avalos.It Fl 6 60664f4763SzrjForce 6118de8d7fSPeter Avalos.Nm 6218de8d7fSPeter Avalosto use IPv6 addresses only. 63e9778795SPeter Avalos.It Fl c 64e9778795SPeter AvalosRequest certificates from target hosts instead of plain keys. 65664f4763Szrj.It Fl D 66664f4763SzrjPrint keys found as SSHFP DNS records. 67664f4763SzrjThe default is to print keys in a format usable as a 68664f4763Szrj.Xr ssh 1 69664f4763Szrj.Pa known_hosts 70664f4763Szrjfile. 7118de8d7fSPeter Avalos.It Fl f Ar file 7218de8d7fSPeter AvalosRead hosts or 7336e94dc5SPeter Avalos.Dq addrlist namelist 7436e94dc5SPeter Avalospairs from 7536e94dc5SPeter Avalos.Ar file , 7636e94dc5SPeter Avalosone per line. 7718de8d7fSPeter AvalosIf 78664f4763Szrj.Sq - 7918de8d7fSPeter Avalosis supplied instead of a filename, 8018de8d7fSPeter Avalos.Nm 81664f4763Szrjwill read from the standard input. 82*ba1276acSMatthew DillonNames read from a file must start with an address, hostname or CIDR network 83*ba1276acSMatthew Dillonrange to be scanned. 84*ba1276acSMatthew DillonAddresses and hostnames may optionally be followed by comma-separated name 85*ba1276acSMatthew Dillonor address aliases that will be copied to the output. 86*ba1276acSMatthew DillonFor example: 87664f4763Szrj.Bd -literal 88*ba1276acSMatthew Dillon192.168.11.0/24 89*ba1276acSMatthew Dillon10.20.1.1 90*ba1276acSMatthew Dillonhappy.example.org 91*ba1276acSMatthew Dillon10.0.0.1,sad.example.org 92664f4763Szrj.Ed 9318de8d7fSPeter Avalos.It Fl H 9418de8d7fSPeter AvalosHash all hostnames and addresses in the output. 9518de8d7fSPeter AvalosHashed names may be used normally by 96664f4763Szrj.Xr ssh 1 9718de8d7fSPeter Avalosand 98664f4763Szrj.Xr sshd 8 , 9918de8d7fSPeter Avalosbut they do not reveal identifying information should the file's contents 10018de8d7fSPeter Avalosbe disclosed. 101*ba1276acSMatthew Dillon.It Fl O Ar option 102*ba1276acSMatthew DillonSpecify a key/value option. 103*ba1276acSMatthew DillonAt present, only a single option is supported: 104*ba1276acSMatthew Dillon.Bl -tag -width Ds 105*ba1276acSMatthew Dillon.It Cm hashalg Ns = Ns Ar algorithm 106*ba1276acSMatthew DillonSelects a hash algorithm to use when printing SSHFP records using the 107*ba1276acSMatthew Dillon.Fl D 108*ba1276acSMatthew Dillonflag. 109*ba1276acSMatthew DillonValid algorithms are 110*ba1276acSMatthew Dillon.Dq sha1 111*ba1276acSMatthew Dillonand 112*ba1276acSMatthew Dillon.Dq sha256 . 113*ba1276acSMatthew DillonThe default is to print both. 114*ba1276acSMatthew Dillon.El 11518de8d7fSPeter Avalos.It Fl p Ar port 116664f4763SzrjConnect to 117664f4763Szrj.Ar port 118664f4763Szrjon the remote host. 119*ba1276acSMatthew Dillon.It Fl q 120*ba1276acSMatthew DillonQuiet mode: 121*ba1276acSMatthew Dillondo not print server host name and banners in comments. 12218de8d7fSPeter Avalos.It Fl T Ar timeout 12318de8d7fSPeter AvalosSet the timeout for connection attempts. 12418de8d7fSPeter AvalosIf 12536e94dc5SPeter Avalos.Ar timeout 12618de8d7fSPeter Avalosseconds have elapsed since a connection was initiated to a host or since the 127664f4763Szrjlast time anything was read from that host, the connection is 12818de8d7fSPeter Avalosclosed and the host in question considered unavailable. 129664f4763SzrjThe default is 5 seconds. 13018de8d7fSPeter Avalos.It Fl t Ar type 131664f4763SzrjSpecify the type of the key to fetch from the scanned hosts. 13218de8d7fSPeter AvalosThe possible values are 13336e94dc5SPeter Avalos.Dq ecdsa , 13436e94dc5SPeter Avalos.Dq ed25519 , 135ee116499SAntonio Huete Jimenez.Dq ecdsa-sk , 136ee116499SAntonio Huete Jimenez.Dq ed25519-sk , 13718de8d7fSPeter Avalosor 138ce74bacaSMatthew Dillon.Dq rsa . 13918de8d7fSPeter AvalosMultiple values may be specified by separating them with commas. 140*ba1276acSMatthew DillonThe default is to fetch all the above key types. 14118de8d7fSPeter Avalos.It Fl v 142664f4763SzrjVerbose mode: 143664f4763Szrjprint debugging messages about progress. 14418de8d7fSPeter Avalos.El 145664f4763Szrj.Pp 14618de8d7fSPeter AvalosIf an ssh_known_hosts file is constructed using 14718de8d7fSPeter Avalos.Nm 14818de8d7fSPeter Avaloswithout verifying the keys, users will be vulnerable to 14918de8d7fSPeter Avalos.Em man in the middle 15018de8d7fSPeter Avalosattacks. 15118de8d7fSPeter AvalosOn the other hand, if the security model allows such a risk, 15218de8d7fSPeter Avalos.Nm 15318de8d7fSPeter Avaloscan help in the detection of tampered keyfiles or man in the middle 15418de8d7fSPeter Avalosattacks which have begun after the ssh_known_hosts file was created. 15518de8d7fSPeter Avalos.Sh FILES 15618de8d7fSPeter Avalos.Pa /etc/ssh/ssh_known_hosts 15718de8d7fSPeter Avalos.Sh EXAMPLES 158664f4763SzrjPrint the RSA host key for machine 15936e94dc5SPeter Avalos.Ar hostname : 160664f4763Szrj.Pp 161664f4763Szrj.Dl $ ssh-keyscan -t rsa hostname 16218de8d7fSPeter Avalos.Pp 163*ba1276acSMatthew DillonSearch a network range, printing all supported key types: 164*ba1276acSMatthew Dillon.Pp 165*ba1276acSMatthew Dillon.Dl $ ssh-keyscan 192.168.0.64/25 166*ba1276acSMatthew Dillon.Pp 16718de8d7fSPeter AvalosFind all hosts from the file 16818de8d7fSPeter Avalos.Pa ssh_hosts 16918de8d7fSPeter Avaloswhich have new or different keys from those in the sorted file 17018de8d7fSPeter Avalos.Pa ssh_known_hosts : 171664f4763Szrj.Bd -literal -offset indent 172*ba1276acSMatthew Dillon$ ssh-keyscan -t rsa,ecdsa,ed25519 -f ssh_hosts | \e 17318de8d7fSPeter Avalos sort -u - ssh_known_hosts | diff ssh_known_hosts - 17418de8d7fSPeter Avalos.Ed 17518de8d7fSPeter Avalos.Sh SEE ALSO 17618de8d7fSPeter Avalos.Xr ssh 1 , 17718de8d7fSPeter Avalos.Xr sshd 8 178664f4763Szrj.Rs 179664f4763Szrj.%D 2006 180664f4763Szrj.%R RFC 4255 181664f4763Szrj.%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints 182664f4763Szrj.Re 18318de8d7fSPeter Avalos.Sh AUTHORS 18418de8d7fSPeter Avalos.An -nosplit 18536e94dc5SPeter Avalos.An David Mazieres Aq Mt dm@lcs.mit.edu 18618de8d7fSPeter Avaloswrote the initial version, and 18736e94dc5SPeter Avalos.An Wayne Davison Aq Mt wayned@users.sourceforge.net 18818de8d7fSPeter Avalosadded support for protocol version 2. 189