ssh-copy-id.1 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. .ig \" -*- nroff -*-
  2. Copyright (c) 1999-2016 hands.com Ltd. <http://hands.com/>
  3. Redistribution and use in source and binary forms, with or without
  4. modification, are permitted provided that the following conditions
  5. are met:
  6. 1. Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. 2. Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  12. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  13. OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  14. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  15. INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  16. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  17. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  18. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  19. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  20. THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  21. ..
  22. .Dd $Mdocdate: June 17 2010 $
  23. .Dt SSH-COPY-ID 1
  24. .Os
  25. .Sh NAME
  26. .Nm ssh-copy-id
  27. .Nd use locally available keys to authorise logins on a remote machine
  28. .Sh SYNOPSIS
  29. .Nm
  30. .Op Fl f
  31. .Op Fl n
  32. .Op Fl i Op Ar identity_file
  33. .Op Fl p Ar port
  34. .Op Fl o Ar ssh_option
  35. .Op Ar user Ns @ Ns
  36. .Ar hostname
  37. .Nm
  38. .Fl h | Fl ?
  39. .br
  40. .Sh DESCRIPTION
  41. .Nm
  42. is a script that uses
  43. .Xr ssh 1
  44. to log into a remote machine (presumably using a login password,
  45. so password authentication should be enabled, unless you've done some
  46. clever use of multiple identities). It assembles a list of one or more
  47. fingerprints (as described below) and tries to log in with each key, to
  48. see if any of them are already installed (of course, if you are not using
  49. .Xr ssh-agent 1
  50. this may result in you being repeatedly prompted for pass-phrases).
  51. It then assembles a list of those that failed to log in, and using ssh,
  52. enables logins with those keys on the remote server. By default it adds
  53. the keys by appending them to the remote user's
  54. .Pa ~/.ssh/authorized_keys
  55. (creating the file, and directory, if necessary). It is also capable
  56. of detecting if the remote system is a NetScreen, and using its
  57. .Ql set ssh pka-dsa key ...
  58. command instead.
  59. .Pp
  60. The options are as follows:
  61. .Bl -tag -width Ds
  62. .It Fl i Ar identity_file
  63. Use only the key(s) contained in
  64. .Ar identity_file
  65. (rather than looking for identities via
  66. .Xr ssh-add 1
  67. or in the
  68. .Ic default_ID_file ) .
  69. If the filename does not end in
  70. .Pa .pub
  71. this is added. If the filename is omitted, the
  72. .Ic default_ID_file
  73. is used.
  74. .Pp
  75. Note that this can be used to ensure that the keys copied have the
  76. comment one prefers and/or extra options applied, by ensuring that the
  77. key file has these set as preferred before the copy is attempted.
  78. .It Fl f
  79. Forced mode: doesn't check if the keys are present on the remote server.
  80. This means that it does not need the private key. Of course, this can result
  81. in more than one copy of the key being installed on the remote system.
  82. .It Fl n
  83. do a dry-run. Instead of installing keys on the remote system simply
  84. prints the key(s) that would have been installed.
  85. .It Fl h , Fl ?
  86. Print Usage summary
  87. .It Fl p Ar port , Fl o Ar ssh_option
  88. These two options are simply passed through untouched, along with their
  89. argument, to allow one to set the port or other
  90. .Xr ssh 1
  91. options, respectively.
  92. .Pp
  93. Rather than specifying these as command line options, it is often better to use (per-host) settings in
  94. .Xr ssh 1 Ns 's
  95. configuration file:
  96. .Xr ssh_config 5 .
  97. .El
  98. .Pp
  99. Default behaviour without
  100. .Fl i ,
  101. is to check if
  102. .Ql ssh-add -L
  103. provides any output, and if so those keys are used. Note that this results in
  104. the comment on the key being the filename that was given to
  105. .Xr ssh-add 1
  106. when the key was loaded into your
  107. .Xr ssh-agent 1
  108. rather than the comment contained in that file, which is a bit of a shame.
  109. Otherwise, if
  110. .Xr ssh-add 1
  111. provides no keys contents of the
  112. .Ic default_ID_file
  113. will be used.
  114. .Pp
  115. The
  116. .Ic default_ID_file
  117. is the most recent file that matches:
  118. .Pa ~/.ssh/id*.pub ,
  119. (excluding those that match
  120. .Pa ~/.ssh/*-cert.pub )
  121. so if you create a key that is not the one you want
  122. .Nm
  123. to use, just use
  124. .Xr touch 1
  125. on your preferred key's
  126. .Pa .pub
  127. file to reinstate it as the most recent.
  128. .Pp
  129. .Sh EXAMPLES
  130. If you have already installed keys from one system on a lot of remote
  131. hosts, and you then create a new key, on a new client machine, say,
  132. it can be difficult to keep track of which systems on which you've
  133. installed the new key. One way of dealing with this is to load both
  134. the new key and old key(s) into your
  135. .Xr ssh-agent 1 .
  136. Load the new key first, without the
  137. .Fl c
  138. option, then load one or more old keys into the agent, possibly by
  139. ssh-ing to the client machine that has that old key, using the
  140. .Fl A
  141. option to allow agent forwarding:
  142. .Pp
  143. .D1 user@newclient$ ssh-add
  144. .D1 user@newclient$ ssh -A old.client
  145. .D1 user@oldl$ ssh-add -c
  146. .D1 No ... prompt for pass-phrase ...
  147. .D1 user@old$ logoff
  148. .D1 user@newclient$ ssh someserver
  149. .Pp
  150. now, if the new key is installed on the server, you'll be allowed in
  151. unprompted, whereas if you only have the old key(s) enabled, you'll be
  152. asked for confirmation, which is your cue to log back out and run
  153. .Pp
  154. .D1 user@newclient$ ssh-copy-id -i someserver
  155. .Pp
  156. The reason you might want to specify the -i option in this case is to
  157. ensure that the comment on the installed key is the one from the
  158. .Pa .pub
  159. file, rather than just the filename that was loaded into your agent.
  160. It also ensures that only the id you intended is installed, rather than
  161. all the keys that you have in your
  162. .Xr ssh-agent 1 .
  163. Of course, you can specify another id, or use the contents of the
  164. .Xr ssh-agent 1
  165. as you prefer.
  166. .Pp
  167. Having mentioned
  168. .Xr ssh-add 1 Ns 's
  169. .Fl c
  170. option, you might consider using this whenever using agent forwarding
  171. to avoid your key being hijacked, but it is much better to instead use
  172. .Xr ssh 1 Ns 's
  173. .Ar ProxyCommand
  174. and
  175. .Fl W
  176. option,
  177. to bounce through remote servers while always doing direct end-to-end
  178. authentication. This way the middle hop(s) don't get access to your
  179. .Xr ssh-agent 1 .
  180. A web search for
  181. .Ql ssh proxycommand nc
  182. should prove enlightening (N.B. the modern approach is to use the
  183. .Fl W
  184. option, rather than
  185. .Xr nc 1 ) .
  186. .Sh "SEE ALSO"
  187. .Xr ssh 1 ,
  188. .Xr ssh-agent 1 ,
  189. .Xr sshd 8