ssh-keyscan.1 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. .\" $OpenBSD: ssh-keyscan.1,v 1.45 2019/11/30 07:07:59 jmc Exp $
  2. .\"
  3. .\" Copyright 1995, 1996 by David Mazieres <dm@lcs.mit.edu>.
  4. .\"
  5. .\" Modification and redistribution in source and binary forms is
  6. .\" permitted provided that due credit is given to the author and the
  7. .\" OpenBSD project by leaving this copyright notice intact.
  8. .\"
  9. .Dd $Mdocdate: November 30 2019 $
  10. .Dt SSH-KEYSCAN 1
  11. .Os
  12. .Sh NAME
  13. .Nm ssh-keyscan
  14. .Nd gather SSH public keys from servers
  15. .Sh SYNOPSIS
  16. .Nm ssh-keyscan
  17. .Op Fl 46cDHv
  18. .Op Fl f Ar file
  19. .Op Fl p Ar port
  20. .Op Fl T Ar timeout
  21. .Op Fl t Ar type
  22. .Op Ar host | addrlist namelist
  23. .Sh DESCRIPTION
  24. .Nm
  25. is a utility for gathering the public SSH host keys of a number of
  26. hosts.
  27. It was designed to aid in building and verifying
  28. .Pa ssh_known_hosts
  29. files,
  30. the format of which is documented in
  31. .Xr sshd 8 .
  32. .Nm
  33. provides a minimal interface suitable for use by shell and perl
  34. scripts.
  35. .Pp
  36. .Nm
  37. uses non-blocking socket I/O to contact as many hosts as possible in
  38. parallel, so it is very efficient.
  39. The keys from a domain of 1,000
  40. hosts can be collected in tens of seconds, even when some of those
  41. hosts are down or do not run
  42. .Xr sshd 8 .
  43. For scanning, one does not need
  44. login access to the machines that are being scanned, nor does the
  45. scanning process involve any encryption.
  46. .Pp
  47. The options are as follows:
  48. .Bl -tag -width Ds
  49. .It Fl 4
  50. Force
  51. .Nm
  52. to use IPv4 addresses only.
  53. .It Fl 6
  54. Force
  55. .Nm
  56. to use IPv6 addresses only.
  57. .It Fl c
  58. Request certificates from target hosts instead of plain keys.
  59. .It Fl D
  60. Print keys found as SSHFP DNS records.
  61. The default is to print keys in a format usable as a
  62. .Xr ssh 1
  63. .Pa known_hosts
  64. file.
  65. .It Fl f Ar file
  66. Read hosts or
  67. .Dq addrlist namelist
  68. pairs from
  69. .Ar file ,
  70. one per line.
  71. If
  72. .Sq -
  73. is supplied instead of a filename,
  74. .Nm
  75. will read from the standard input.
  76. Input is expected in the format:
  77. .Bd -literal
  78. 1.2.3.4,1.2.4.4 name.my.domain,name,n.my.domain,n,1.2.3.4,1.2.4.4
  79. .Ed
  80. .It Fl H
  81. Hash all hostnames and addresses in the output.
  82. Hashed names may be used normally by
  83. .Xr ssh 1
  84. and
  85. .Xr sshd 8 ,
  86. but they do not reveal identifying information should the file's contents
  87. be disclosed.
  88. .It Fl p Ar port
  89. Connect to
  90. .Ar port
  91. on the remote host.
  92. .It Fl T Ar timeout
  93. Set the timeout for connection attempts.
  94. If
  95. .Ar timeout
  96. seconds have elapsed since a connection was initiated to a host or since the
  97. last time anything was read from that host, the connection is
  98. closed and the host in question considered unavailable.
  99. The default is 5 seconds.
  100. .It Fl t Ar type
  101. Specify the type of the key to fetch from the scanned hosts.
  102. The possible values are
  103. .Dq dsa ,
  104. .Dq ecdsa ,
  105. .Dq ed25519 ,
  106. or
  107. .Dq rsa .
  108. Multiple values may be specified by separating them with commas.
  109. The default is to fetch
  110. .Dq rsa ,
  111. .Dq ecdsa ,
  112. and
  113. .Dq ed25519
  114. keys.
  115. .It Fl v
  116. Verbose mode:
  117. print debugging messages about progress.
  118. .El
  119. .Pp
  120. If an ssh_known_hosts file is constructed using
  121. .Nm
  122. without verifying the keys, users will be vulnerable to
  123. .Em man in the middle
  124. attacks.
  125. On the other hand, if the security model allows such a risk,
  126. .Nm
  127. can help in the detection of tampered keyfiles or man in the middle
  128. attacks which have begun after the ssh_known_hosts file was created.
  129. .Sh FILES
  130. .Pa /etc/ssh/ssh_known_hosts
  131. .Sh EXAMPLES
  132. Print the RSA host key for machine
  133. .Ar hostname :
  134. .Pp
  135. .Dl $ ssh-keyscan -t rsa hostname
  136. .Pp
  137. Find all hosts from the file
  138. .Pa ssh_hosts
  139. which have new or different keys from those in the sorted file
  140. .Pa ssh_known_hosts :
  141. .Bd -literal -offset indent
  142. $ ssh-keyscan -t rsa,dsa,ecdsa,ed25519 -f ssh_hosts | \e
  143. sort -u - ssh_known_hosts | diff ssh_known_hosts -
  144. .Ed
  145. .Sh SEE ALSO
  146. .Xr ssh 1 ,
  147. .Xr sshd 8
  148. .Rs
  149. .%D 2006
  150. .%R RFC 4255
  151. .%T Using DNS to Securely Publish Secure Shell (SSH) Key Fingerprints
  152. .Re
  153. .Sh AUTHORS
  154. .An -nosplit
  155. .An David Mazieres Aq Mt dm@lcs.mit.edu
  156. wrote the initial version, and
  157. .An Wayne Davison Aq Mt wayned@users.sourceforge.net
  158. added support for protocol version 2.