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] [-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
18     installed (of course, if you are not using ssh-agent(1) this may result
19     in 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
24     remote system is a NetScreen, and using its ‘set ssh pka-dsa key ...’
25     command 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     -h, -?  Print Usage summary
49
50     -p port, -o ssh_option
51             These two options are simply passed through untouched, along with
52             their argument, to allow one to set the port or other ssh(1)
53             options, respectively.
54
55             Rather than specifying these as command line options, it is often
56             better to use (per-host) settings in ssh(1)'s configuration file:
57             ssh_config(5).
58
59     Default behaviour without -i, is to check if ‘ssh-add -L’ provides any
60     output, and if so those keys are used.  Note that this results in the
61     comment on the key being the filename that was given to ssh-add(1) when
62     the key was loaded into your ssh-agent(1) rather than the comment con‐
63     tained in that file, which is a bit of a shame.  Otherwise, if ssh-add(1)
64     provides no keys contents of the default_ID_file will be used.
65
66     The default_ID_file is the most recent file that matches: ~/.ssh/id*.pub,
67     (excluding those that match ~/.ssh/*-cert.pub) so if you create a key
68     that is not the one you want ssh-copy-id to use, just use touch(1) on
69     your preferred key's .pub file to reinstate it as the most recent.
70

EXAMPLES

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

SEE ALSO

111     ssh(1), ssh-agent(1), sshd(8)
112
113BSD                              May 10, 2020                              BSD
Impressum