How to ssh-copy-id 2nd key when the server only allows publickey authentication
ssh-copy-id
appends keys to the remote authorized_keys
file. To add several specific keys, run it once per key with -I <key-file-name>
.
Update
After your comment, I think I got your question wrong.
You want to use one key to authenticate while installing another on your server.
ssh-copy-id
does not offer a command-line option to choose a key for authenticating while executing ssh-copy-id
.
But it passes -o
through to ssh
. So:
ssh-copy-id -i ~/.ssh/<your-new-id-to-install> -o 'IdentityFile ~/.ssh/<your-already-existing-id>' <servername>
You can also use ssh-agent
, in which case you won't have to enter your passphrase when using ssh
, scp
, ssh-copy-id
, a.s.o. for as long as ssh-agent
is running.
Using ssh-add
to add your key to the agent is definetly an option.
Otherwise I believe you'd have to set up an entry in the .ssh/config file which includes an IdentityFile option, this will tell ssh how to authenticate for that server and allow ssh-copy-id to do its thing.