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