1.ig \" -*- nroff -*- 2Copyright (c) 1999-2013 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 i Op Ar identity_file 35.Op Fl p Ar port 36.Op Fl o Ar ssh_option 37.Op Ar user Ns @ Ns 38.Ar hostname 39.Nm 40.Fl h | Fl ? 41.br 42.Sh DESCRIPTION 43.Nm 44is a script that uses 45.Xr ssh 1 46to log into a remote machine (presumably using a login password, 47so password authentication should be enabled, unless you've done some 48clever use of multiple identities). It assembles a list of one or more 49fingerprints (as described below) and tries to log in with each key, to 50see if any of them are already installed (of course, if you are not using 51.Xr ssh-agent 1 52this may result in you being repeatedly prompted for pass-phrases). 53It then assembles a list of those that failed to log in, and using ssh, 54enables logins with those keys on the remote server. By default it adds 55the keys by appending them to the remote user's 56.Pa ~/.ssh/authorized_keys 57(creating the file, and directory, if necessary). It is also capable 58of detecting if the remote system is a NetScreen, and using its 59.Ql set ssh pka-dsa key ... 60command instead. 61.Pp 62The options are as follows: 63.Bl -tag -width Ds 64.It Fl i Ar identity_file 65Use only the key(s) contained in 66.Ar identity_file 67(rather than looking for identities via 68.Xr ssh-add 1 69or in the 70.Ic default_ID_file ) . 71If the filename does not end in 72.Pa .pub 73this is added. If the filename is omitted, the 74.Ic default_ID_file 75is used. 76.Pp 77Note that this can be used to ensure that the keys copied have the 78comment one prefers and/or extra options applied, by ensuring that the 79key file has these set as preferred before the copy is attempted. 80.It Fl f 81Forced mode: doesn't check if the keys are present on the remote server. 82This means that it does not need the private key. Of course, this can result 83in more than one copy of the key being installed on the remote system. 84.It Fl n 85do a dry-run. Instead of installing keys on the remote system simply 86prints the key(s) that would have been installed. 87.It Fl h , Fl ? 88Print Usage summary 89.It Fl p Ar port , Fl o Ar ssh_option 90These two options are simply passed through untouched, along with their 91argument, to allow one to set the port or other 92.Xr ssh 1 93options, respectively. 94.Pp 95Rather than specifying these as command line options, it is often better to use (per-host) settings in 96.Xr ssh 1 Ns 's 97configuration file: 98.Xr ssh_config 5 . 99.El 100.Pp 101Default behaviour without 102.Fl i , 103is to check if 104.Ql ssh-add -L 105provides any output, and if so those keys are used. Note that this results in 106the comment on the key being the filename that was given to 107.Xr ssh-add 1 108when the key was loaded into your 109.Xr ssh-agent 1 110rather than the comment contained in that file, which is a bit of a shame. 111Otherwise, if 112.Xr ssh-add 1 113provides no keys contents of the 114.Ic default_ID_file 115will be used. 116.Pp 117The 118.Ic default_ID_file 119is the most recent file that matches: 120.Pa ~/.ssh/id*.pub , 121(excluding those that match 122.Pa ~/.ssh/*-cert.pub ) 123so if you create a key that is not the one you want 124.Nm 125to use, just use 126.Xr touch 1 127on your preferred key's 128.Pa .pub 129file to reinstate it as the most recent. 130.Pp 131.Sh EXAMPLES 132If you have already installed keys from one system on a lot of remote 133hosts, and you then create a new key, on a new client machine, say, 134it can be difficult to keep track of which systems on which you've 135installed the new key. One way of dealing with this is to load both 136the new key and old key(s) into your 137.Xr ssh-agent 1 . 138Load the new key first, without the 139.Fl c 140option, then load one or more old keys into the agent, possibly by 141ssh-ing to the client machine that has that old key, using the 142.Fl A 143option to allow agent forwarding: 144.Pp 145.D1 user@newclient$ ssh-add 146.D1 user@newclient$ ssh -A old.client 147.D1 user@oldl$ ssh-add -c 148.D1 No ... prompt for pass-phrase ... 149.D1 user@old$ logoff 150.D1 user@newclient$ ssh someserver 151.Pp 152now, if the new key is installed on the server, you'll be allowed in 153unprompted, whereas if you only have the old key(s) enabled, you'll be 154asked for confirmation, which is your cue to log back out and run 155.Pp 156.D1 user@newclient$ ssh-copy-id -i someserver 157.Pp 158The reason you might want to specify the -i option in this case is to 159ensure that the comment on the installed key is the one from the 160.Pa .pub 161file, rather than just the filename that was loaded into you agent. 162It also ensures that only the id you intended is installed, rather than 163all the keys that you have in your 164.Xr ssh-agent 1 . 165Of course, you can specify another id, or use the contents of the 166.Xr ssh-agent 1 167as you prefer. 168.Pp 169Having mentioned 170.Xr ssh-add 1 Ns 's 171.Fl c 172option, you might consider using this whenever using agent forwarding 173to avoid your key being hijacked, but it is much better to instead use 174.Xr ssh 1 Ns 's 175.Ar ProxyCommand 176and 177.Fl W 178option, 179to bounce through remote servers while always doing direct end-to-end 180authentication. This way the middle hop(s) don't get access to your 181.Xr ssh-agent 1 . 182A web search for 183.Ql ssh proxycommand nc 184should prove enlightening (N.B. the modern approach is to use the 185.Fl W 186option, rather than 187.Xr nc 1 ) . 188.Sh "SEE ALSO" 189.Xr ssh 1 , 190.Xr ssh-agent 1 , 191.Xr sshd 8 192