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