xref: /freebsd/crypto/openssh/contrib/ssh-copy-id.1 (revision 3d9fd9fcb432750f3716b28f6ccb0104cd9d351a)
1ce3adf43SDag-Erling Smørgrav.ig \"  -*- nroff -*-
2*3d9fd9fcSEd MasteCopyright (c) 1999-2024 Philip Hands <phil@hands.com>
3ce3adf43SDag-Erling Smørgrav
4ce3adf43SDag-Erling SmørgravRedistribution and use in source and binary forms, with or without
5ce3adf43SDag-Erling Smørgravmodification, are permitted provided that the following conditions
6ce3adf43SDag-Erling Smørgravare met:
7ce3adf43SDag-Erling Smørgrav1. Redistributions of source code must retain the above copyright
8ce3adf43SDag-Erling Smørgrav   notice, this list of conditions and the following disclaimer.
9ce3adf43SDag-Erling Smørgrav2. Redistributions in binary form must reproduce the above copyright
10ce3adf43SDag-Erling Smørgrav   notice, this list of conditions and the following disclaimer in the
11ce3adf43SDag-Erling Smørgrav   documentation and/or other materials provided with the distribution.
12ce3adf43SDag-Erling Smørgrav
13ce3adf43SDag-Erling SmørgravTHIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14ce3adf43SDag-Erling SmørgravIMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15ce3adf43SDag-Erling SmørgravOF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16ce3adf43SDag-Erling SmørgravIN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17ce3adf43SDag-Erling SmørgravINCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18ce3adf43SDag-Erling SmørgravNOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19ce3adf43SDag-Erling SmørgravDATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20ce3adf43SDag-Erling SmørgravTHEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21ce3adf43SDag-Erling Smørgrav(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22ce3adf43SDag-Erling SmørgravTHIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23ce3adf43SDag-Erling Smørgrav..
24845c9bd1SDag-Erling Smørgrav.Dd $Mdocdate: June 17 2010 $
25ce3adf43SDag-Erling Smørgrav.Dt SSH-COPY-ID 1
26ce3adf43SDag-Erling Smørgrav.Os
27ce3adf43SDag-Erling Smørgrav.Sh NAME
28ce3adf43SDag-Erling Smørgrav.Nm ssh-copy-id
29ce3adf43SDag-Erling Smørgrav.Nd use locally available keys to authorise logins on a remote machine
30ce3adf43SDag-Erling Smørgrav.Sh SYNOPSIS
31ce3adf43SDag-Erling Smørgrav.Nm
32acc1a9efSDag-Erling Smørgrav.Op Fl f
33ce3adf43SDag-Erling Smørgrav.Op Fl n
3419261079SEd Maste.Op Fl s
35535af610SEd Maste.Op Fl x
36ce3adf43SDag-Erling Smørgrav.Op Fl i Op Ar identity_file
37535af610SEd Maste.Op Fl t Ar target_path
38*3d9fd9fcSEd Maste.Op Fl F Ar ssh_config
39*3d9fd9fcSEd Maste.Op Bo Fl o Ar ssh_option Bc ...
40*3d9fd9fcSEd Maste.Op Fl p Ar port
41ce3adf43SDag-Erling Smørgrav.Op Ar user Ns @ Ns
42ce3adf43SDag-Erling Smørgrav.Ar hostname
43ce3adf43SDag-Erling Smørgrav.Nm
44ce3adf43SDag-Erling Smørgrav.Fl h | Fl ?
45ce3adf43SDag-Erling Smørgrav.br
46ce3adf43SDag-Erling Smørgrav.Sh DESCRIPTION
47ce3adf43SDag-Erling Smørgrav.Nm
48ce3adf43SDag-Erling Smørgravis a script that uses
49ce3adf43SDag-Erling Smørgrav.Xr ssh 1
50ce3adf43SDag-Erling Smørgravto log into a remote machine (presumably using a login password,
51ce3adf43SDag-Erling Smørgravso password authentication should be enabled, unless you've done some
52535af610SEd Masteclever use of multiple identities).
53535af610SEd MasteIt assembles a list of one or more fingerprints (as described below)
54535af610SEd Masteand tries to log in with each key,
55535af610SEd Masteto see if any of them are already installed (of course, if you are not using
56ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1
57ce3adf43SDag-Erling Smørgravthis may result in you being repeatedly prompted for pass-phrases).
58535af610SEd MasteIt then assembles a list of those that failed to log in and, using
59535af610SEd Maste.Xr ssh 1 ,
60535af610SEd Masteenables logins with those keys on the remote server.
61535af610SEd MasteBy default it adds the keys by appending them to the remote user's
62ce3adf43SDag-Erling Smørgrav.Pa ~/.ssh/authorized_keys
63535af610SEd Maste(creating the file, and directory, if necessary).
64535af610SEd MasteIt is also capable of detecting if the remote system is a NetScreen,
65535af610SEd Masteand using its
66ce3adf43SDag-Erling Smørgrav.Ql set ssh pka-dsa key ...
67ce3adf43SDag-Erling Smørgravcommand instead.
68ce3adf43SDag-Erling Smørgrav.Pp
69ce3adf43SDag-Erling SmørgravThe options are as follows:
70ce3adf43SDag-Erling Smørgrav.Bl -tag -width Ds
71*3d9fd9fcSEd Maste.It Fl i Op Ar identity_file
72ce3adf43SDag-Erling SmørgravUse only the key(s) contained in
73ce3adf43SDag-Erling Smørgrav.Ar identity_file
74ce3adf43SDag-Erling Smørgrav(rather than looking for identities via
75ce3adf43SDag-Erling Smørgrav.Xr ssh-add 1
76ce3adf43SDag-Erling Smørgravor in the
77ce3adf43SDag-Erling Smørgrav.Ic default_ID_file ) .
78ce3adf43SDag-Erling SmørgravIf the filename does not end in
79ce3adf43SDag-Erling Smørgrav.Pa .pub
80535af610SEd Mastethis is added.
81535af610SEd MasteIf the filename is omitted, the
82ce3adf43SDag-Erling Smørgrav.Ic default_ID_file
83ce3adf43SDag-Erling Smørgravis used.
84ce3adf43SDag-Erling Smørgrav.Pp
85ce3adf43SDag-Erling SmørgravNote that this can be used to ensure that the keys copied have the
86ce3adf43SDag-Erling Smørgravcomment one prefers and/or extra options applied, by ensuring that the
87ce3adf43SDag-Erling Smørgravkey file has these set as preferred before the copy is attempted.
88acc1a9efSDag-Erling Smørgrav.It Fl f
89acc1a9efSDag-Erling SmørgravForced mode: doesn't check if the keys are present on the remote server.
90535af610SEd MasteThis means that it does not need the private key.
91535af610SEd MasteOf course, this can result in more than one copy of the key being installed
92535af610SEd Masteon the remote system.
93ce3adf43SDag-Erling Smørgrav.It Fl n
94535af610SEd Mastedo a dry-run.
95535af610SEd MasteInstead of installing keys on the remote system simply
96ce3adf43SDag-Erling Smørgravprints the key(s) that would have been installed.
9719261079SEd Maste.It Fl s
98535af610SEd MasteSFTP mode: usually the public keys are installed
99535af610SEd Masteby executing commands on the remote side.
10019261079SEd MasteWith this option the user's
10119261079SEd Maste.Pa ~/.ssh/authorized_keys
10219261079SEd Mastefile will be downloaded, modified locally and uploaded with sftp.
103535af610SEd MasteThis option is useful if the server has restrictions
104535af610SEd Masteon commands which can be used on the remote side.
105535af610SEd Maste.It Fl t Ar target_path
106535af610SEd Mastethe path on the target system where the keys should be added
107535af610SEd Maste(defaults to ".ssh/authorized_keys")
108*3d9fd9fcSEd Maste.It Fl p Ar port
109*3d9fd9fcSEd MasteSpecifies the port to connect to on the remote host.
110*3d9fd9fcSEd Maste.It Fl F Ar ssh_config , Fl o Ar ssh_option
111*3d9fd9fcSEd MasteThese options are simply passed through untouched (with their argument)
112*3d9fd9fcSEd Masteto ssh/sftp,
113*3d9fd9fcSEd Masteallowing one to set an alternative config file,
114*3d9fd9fcSEd Masteor other options, respectively.
115ce3adf43SDag-Erling Smørgrav.Pp
116535af610SEd MasteRather than specifying these as command line options,
117535af610SEd Masteit is often better to use (per-host) settings in
118ce3adf43SDag-Erling Smørgrav.Xr ssh 1 Ns 's
119ce3adf43SDag-Erling Smørgravconfiguration file:
120ce3adf43SDag-Erling Smørgrav.Xr ssh_config 5 .
121535af610SEd Maste.It Fl x
122535af610SEd MasteThis option is for debugging the
123535af610SEd Maste.Nm
124535af610SEd Mastescript itself.
125535af610SEd MasteIt sets the shell's -x flag, so that you can see the commands being run.
126535af610SEd Maste.It Fl h , Fl ?
127535af610SEd MastePrint Usage summary
128ce3adf43SDag-Erling Smørgrav.El
129ce3adf43SDag-Erling Smørgrav.Pp
130ce3adf43SDag-Erling SmørgravDefault behaviour without
131ce3adf43SDag-Erling Smørgrav.Fl i ,
132ce3adf43SDag-Erling Smørgravis to check if
133ce3adf43SDag-Erling Smørgrav.Ql ssh-add -L
134535af610SEd Masteprovides any output, and if so those keys are used.
135535af610SEd MasteNote that this results in the comment on the key
136535af610SEd Mastebeing the filename that was given to
137ce3adf43SDag-Erling Smørgrav.Xr ssh-add 1
138ce3adf43SDag-Erling Smørgravwhen the key was loaded into your
139ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1
140ce3adf43SDag-Erling Smørgravrather than the comment contained in that file, which is a bit of a shame.
141ce3adf43SDag-Erling SmørgravOtherwise, if
142ce3adf43SDag-Erling Smørgrav.Xr ssh-add 1
143ce3adf43SDag-Erling Smørgravprovides no keys contents of the
144ce3adf43SDag-Erling Smørgrav.Ic default_ID_file
145ce3adf43SDag-Erling Smørgravwill be used.
146ce3adf43SDag-Erling Smørgrav.Pp
147ce3adf43SDag-Erling SmørgravThe
148ce3adf43SDag-Erling Smørgrav.Ic default_ID_file
149ce3adf43SDag-Erling Smørgravis the most recent file that matches:
150ce3adf43SDag-Erling Smørgrav.Pa ~/.ssh/id*.pub ,
151ce3adf43SDag-Erling Smørgrav(excluding those that match
152ce3adf43SDag-Erling Smørgrav.Pa ~/.ssh/*-cert.pub )
153ce3adf43SDag-Erling Smørgravso if you create a key that is not the one you want
154ce3adf43SDag-Erling Smørgrav.Nm
155ce3adf43SDag-Erling Smørgravto use, just use
156ce3adf43SDag-Erling Smørgrav.Xr touch 1
157ce3adf43SDag-Erling Smørgravon your preferred key's
158ce3adf43SDag-Erling Smørgrav.Pa .pub
159ce3adf43SDag-Erling Smørgravfile to reinstate it as the most recent.
160ce3adf43SDag-Erling Smørgrav.Sh EXAMPLES
161ce3adf43SDag-Erling SmørgravIf you have already installed keys from one system on a lot of remote
162ce3adf43SDag-Erling Smørgravhosts, and you then create a new key, on a new client machine, say,
163ce3adf43SDag-Erling Smørgravit can be difficult to keep track of which systems on which you've
164535af610SEd Masteinstalled the new key.
165535af610SEd MasteOne way of dealing with this is to load both the new key and old key(s)
166535af610SEd Masteinto your
167ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1 .
168ce3adf43SDag-Erling SmørgravLoad the new key first, without the
169ce3adf43SDag-Erling Smørgrav.Fl c
170ce3adf43SDag-Erling Smørgravoption, then load one or more old keys into the agent, possibly by
171ce3adf43SDag-Erling Smørgravssh-ing to the client machine that has that old key, using the
172ce3adf43SDag-Erling Smørgrav.Fl A
173ce3adf43SDag-Erling Smørgravoption to allow agent forwarding:
174ce3adf43SDag-Erling Smørgrav.Pp
175ce3adf43SDag-Erling Smørgrav.D1 user@newclient$ ssh-add
176ce3adf43SDag-Erling Smørgrav.D1 user@newclient$ ssh -A old.client
177ce3adf43SDag-Erling Smørgrav.D1 user@oldl$ ssh-add -c
178ce3adf43SDag-Erling Smørgrav.D1 No   ... prompt for pass-phrase ...
179ce3adf43SDag-Erling Smørgrav.D1 user@old$ logoff
180ce3adf43SDag-Erling Smørgrav.D1 user@newclient$ ssh someserver
181ce3adf43SDag-Erling Smørgrav.Pp
182ce3adf43SDag-Erling Smørgravnow, if the new key is installed on the server, you'll be allowed in
183ce3adf43SDag-Erling Smørgravunprompted, whereas if you only have the old key(s) enabled, you'll be
184ce3adf43SDag-Erling Smørgravasked for confirmation, which is your cue to log back out and run
185ce3adf43SDag-Erling Smørgrav.Pp
186ce3adf43SDag-Erling Smørgrav.D1 user@newclient$ ssh-copy-id -i someserver
187ce3adf43SDag-Erling Smørgrav.Pp
188535af610SEd MasteThe reason you might want to specify the
189535af610SEd Maste.Fl i
190535af610SEd Masteoption in this case is to
191ce3adf43SDag-Erling Smørgravensure that the comment on the installed key is the one from the
192ce3adf43SDag-Erling Smørgrav.Pa .pub
19319261079SEd Mastefile, rather than just the filename that was loaded into your agent.
194ce3adf43SDag-Erling SmørgravIt also ensures that only the id you intended is installed, rather than
195ce3adf43SDag-Erling Smørgravall the keys that you have in your
196ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1 .
197ce3adf43SDag-Erling SmørgravOf course, you can specify another id, or use the contents of the
198ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1
199ce3adf43SDag-Erling Smørgravas you prefer.
200ce3adf43SDag-Erling Smørgrav.Pp
201ce3adf43SDag-Erling SmørgravHaving mentioned
202ce3adf43SDag-Erling Smørgrav.Xr ssh-add 1 Ns 's
203ce3adf43SDag-Erling Smørgrav.Fl c
204ce3adf43SDag-Erling Smørgravoption, you might consider using this whenever using agent forwarding
205ce3adf43SDag-Erling Smørgravto avoid your key being hijacked, but it is much better to instead use
206ce3adf43SDag-Erling Smørgrav.Xr ssh 1 Ns 's
207ce3adf43SDag-Erling Smørgrav.Ar ProxyCommand
208ce3adf43SDag-Erling Smørgravand
209ce3adf43SDag-Erling Smørgrav.Fl W
210ce3adf43SDag-Erling Smørgravoption,
211ce3adf43SDag-Erling Smørgravto bounce through remote servers while always doing direct end-to-end
212535af610SEd Masteauthentication.
213535af610SEd MasteThis way the middle hop(s) don't get access to your
214ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1 .
215ce3adf43SDag-Erling SmørgravA web search for
216ce3adf43SDag-Erling Smørgrav.Ql ssh proxycommand nc
217535af610SEd Masteshould prove enlightening (NB the modern approach is to use the
218ce3adf43SDag-Erling Smørgrav.Fl W
219ce3adf43SDag-Erling Smørgravoption, rather than
220ce3adf43SDag-Erling Smørgrav.Xr nc 1 ) .
221ce3adf43SDag-Erling Smørgrav.Sh "SEE ALSO"
222ce3adf43SDag-Erling Smørgrav.Xr ssh 1 ,
223ce3adf43SDag-Erling Smørgrav.Xr ssh-agent 1 ,
224ce3adf43SDag-Erling Smørgrav.Xr sshd 8
225