1SSH-KEYSCAN(1)            BSD General Commands Manual           SSH-KEYSCAN(1)
2

NAME

4     ssh-keyscan — gather ssh public keys
5

SYNOPSIS

7     ssh-keyscan [-46cHv] [-f file] [-p port] [-T timeout] [-t type]
8                 [host | addrlist namelist] ...
9

DESCRIPTION

11     ssh-keyscan is a utility for gathering the public ssh host keys of a num‐
12     ber of hosts.  It was designed to aid in building and verifying
13     ssh_known_hosts files.  ssh-keyscan provides a minimal interface suitable
14     for use by shell and perl scripts.
15
16     ssh-keyscan uses non-blocking socket I/O to contact as many hosts as pos‐
17     sible in parallel, so it is very efficient.  The keys from a domain of
18     1,000 hosts can be collected in tens of seconds, even when some of those
19     hosts are down or do not run ssh.  For scanning, one does not need login
20     access to the machines that are being scanned, nor does the scanning
21     process involve any encryption.
22
23     The options are as follows:
24
25     -4      Forces ssh-keyscan to use IPv4 addresses only.
26
27     -6      Forces ssh-keyscan to use IPv6 addresses only.
28
29     -c      Request certificates from target hosts instead of plain keys.
30
31     -f file
32             Read hosts or “addrlist namelist” pairs from file, one per line.
33             If - is supplied instead of a filename, ssh-keyscan will read
34             hosts or “addrlist namelist” pairs from the standard input.
35
36     -H      Hash all hostnames and addresses in the output.  Hashed names may
37             be used normally by ssh and sshd, but they do not reveal identi‐
38             fying information should the file's contents be disclosed.
39
40     -p port
41             Port to connect to on the remote host.
42
43     -T timeout
44             Set the timeout for connection attempts.  If timeout seconds have
45             elapsed since a connection was initiated to a host or since the
46             last time anything was read from that host, then the connection
47             is closed and the host in question considered unavailable.
48             Default is 5 seconds.
49
50     -t type
51             Specifies the type of the key to fetch from the scanned hosts.
52             The possible values are “rsa1” for protocol version 1 and “dsa”,
53             “ecdsa”, “ed25519”, or “rsa” for protocol version 2.  Multiple
54             values may be specified by separating them with commas.  The
55             default is to fetch “rsa”, “ecdsa”, and “ed25519” keys.
56
57     -v      Verbose mode.  Causes ssh-keyscan to print debugging messages
58             about its progress.
59

SECURITY

61     If an ssh_known_hosts file is constructed using ssh-keyscan without veri‐
62     fying the keys, users will be vulnerable to man in the middle attacks.
63     On the other hand, if the security model allows such a risk, ssh-keyscan
64     can help in the detection of tampered keyfiles or man in the middle
65     attacks which have begun after the ssh_known_hosts file was created.
66

FILES

68     Input format:
69
70     1.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4
71
72     Output format for RSA1 keys:
73
74     host-or-namelist bits exponent modulus
75
76     Output format for RSA, DSA, ECDSA, and Ed25519 keys:
77
78     host-or-namelist keytype base64-encoded-key
79
80     Where keytype is either “ecdsa-sha2-nistp256”, “ecdsa-sha2-nistp384”,
81     “ecdsa-sha2-nistp521”, “ssh-ed25519”, “ssh-dss” or “ssh-rsa”.
82
83     /etc/ssh/ssh_known_hosts
84

EXAMPLES

86     Print the rsa host key for machine hostname:
87
88     $ ssh-keyscan hostname
89
90     Find all hosts from the file ssh_hosts which have new or different keys
91     from those in the sorted file ssh_known_hosts:
92
93     $ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \
94             sort -u - ssh_known_hosts | diff ssh_known_hosts -
95

SEE ALSO

97     ssh(1), sshd(8)
98

AUTHORS

100     David Mazieres <dm@lcs.mit.edu> wrote the initial version, and Wayne
101     Davison <wayned@users.sourceforge.net> added support for protocol version
102     2.
103

BUGS

105     It generates "Connection closed by remote host" messages on the consoles
106     of all the machines it scans if the server is older than version 2.9.
107     This is because it opens a connection to the ssh port, reads the public
108     key, and drops the connection as soon as it gets the key.
109
110BSD                              June 21, 2019                             BSD
Impressum