1SSH-COPY-ID(1)            BSD General Commands Manual           SSH-COPY-ID(1)
2

NAME

4     ssh-copy-id — use locally available keys to authorise logins on a remote
5     machine
6

SYNOPSIS

8     ssh-copy-id [-f] [-n] [-s] [-i [identity_file]] [-p port] [-o ssh_option]
9                 [user@]hostname
10     ssh-copy-id -h | -?
11

DESCRIPTION

13     ssh-copy-id is a script that uses ssh(1) to log into a remote machine
14     (presumably using a login password, so password authentication should be
15     enabled, unless you've done some clever use of multiple identities).  It
16     assembles a list of one or more fingerprints (as described below) and
17     tries to log in with each key, to see if any of them are already in‐
18     stalled (of course, if you are not using ssh-agent(1) this may result in
19     you being repeatedly prompted for pass-phrases).  It then assembles a
20     list of those that failed to log in, and using ssh, enables logins with
21     those keys on the remote server.  By default it adds the keys by append‐
22     ing them to the remote user's ~/.ssh/authorized_keys (creating the file,
23     and directory, if necessary).  It is also capable of detecting if the re‐
24     mote system is a NetScreen, and using its ‘set ssh pka-dsa key ...’ com‐
25     mand instead.
26
27     The options are as follows:
28
29     -i identity_file
30             Use only the key(s) contained in identity_file (rather than look‐
31             ing for identities via ssh-add(1) or in the default_ID_file).  If
32             the filename does not end in .pub this is added.  If the filename
33             is omitted, the default_ID_file is used.
34
35             Note that this can be used to ensure that the keys copied have
36             the comment one prefers and/or extra options applied, by ensuring
37             that the key file has these set as preferred before the copy is
38             attempted.
39
40     -f      Forced mode: doesn't check if the keys are present on the remote
41             server.  This means that it does not need the private key.  Of
42             course, this can result in more than one copy of the key being
43             installed on the remote system.
44
45     -n      do a dry-run.  Instead of installing keys on the remote system
46             simply prints the key(s) that would have been installed.
47
48     -s      SFTP mode: usually the public keys are installed by executing
49             commands on the remote side.  With this option the user's
50             ~/.ssh/authorized_keys file will be downloaded, modified locally
51             and uploaded with sftp.  This option is useful if the server has
52             restrictions on commands which can be used on the remote side.
53
54     -h, -?  Print Usage summary
55
56     -p port, -o ssh_option
57             These two options are simply passed through untouched, along with
58             their argument, to allow one to set the port or other ssh(1) op‐
59             tions, respectively.
60
61             Rather than specifying these as command line options, it is often
62             better to use (per-host) settings in ssh(1)'s configuration file:
63             ssh_config(5).
64
65     Default behaviour without -i, is to check if ‘ssh-add -L’ provides any
66     output, and if so those keys are used.  Note that this results in the
67     comment on the key being the filename that was given to ssh-add(1) when
68     the key was loaded into your ssh-agent(1) rather than the comment con‐
69     tained in that file, which is a bit of a shame.  Otherwise, if ssh-add(1)
70     provides no keys contents of the default_ID_file will be used.
71
72     The default_ID_file is the most recent file that matches: ~/.ssh/id*.pub,
73     (excluding those that match ~/.ssh/*-cert.pub) so if you create a key
74     that is not the one you want ssh-copy-id to use, just use touch(1) on
75     your preferred key's .pub file to reinstate it as the most recent.
76

EXAMPLES

78     If you have already installed keys from one system on a lot of remote
79     hosts, and you then create a new key, on a new client machine, say, it
80     can be difficult to keep track of which systems on which you've installed
81     the new key.  One way of dealing with this is to load both the new key
82     and old key(s) into your ssh-agent(1).  Load the new key first, without
83     the -c option, then load one or more old keys into the agent, possibly by
84     ssh-ing to the client machine that has that old key, using the -A option
85     to allow agent forwarding:
86
87           user@newclient$ ssh-add
88           user@newclient$ ssh -A old.client
89           user@oldl$ ssh-add -c
90           ... prompt for pass-phrase ...
91           user@old$ logoff
92           user@newclient$ ssh someserver
93
94     now, if the new key is installed on the server, you'll be allowed in un‐
95     prompted, whereas if you only have the old key(s) enabled, you'll be
96     asked for confirmation, which is your cue to log back out and run
97
98           user@newclient$ ssh-copy-id -i someserver
99
100     The reason you might want to specify the -i option in this case is to en‐
101     sure that the comment on the installed key is the one from the .pub file,
102     rather than just the filename that was loaded into your agent.  It also
103     ensures that only the id you intended is installed, rather than all the
104     keys that you have in your ssh-agent(1).  Of course, you can specify an‐
105     other id, or use the contents of the ssh-agent(1) as you prefer.
106
107     Having mentioned ssh-add(1)'s -c option, you might consider using this
108     whenever using agent forwarding to avoid your key being hijacked, but it
109     is much better to instead use ssh(1)'s ProxyCommand and -W option, to
110     bounce through remote servers while always doing direct end-to-end au‐
111     thentication. This way the middle hop(s) don't get access to your
112     ssh-agent(1).  A web search for ‘ssh proxycommand nc’ should prove en‐
113     lightening (N.B. the modern approach is to use the -W option, rather than
114     nc(1)).
115

SEE ALSO

117     ssh(1), ssh-agent(1), sshd(8)
118
119BSD                              June 17, 2010                             BSD
Impressum