Bug 2128 - ssh-copy-id doesn't check if a public key already exists in a remote servers ~/.ssh/authorized_keys file
Summary: ssh-copy-id doesn't check if a public key already exists in a remote servers ...
Status: CLOSED FIXED
Alias: None
Product: Portable OpenSSH
Classification: Unclassified
Component: ssh-copy-id (show other bugs)
Version: -current
Hardware: Other Other
: P5 enhancement
Assignee: Assigned to nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-16 05:47 AEST by Justin Garrison
Modified: 2016-08-02 10:41 AEST (History)
2 users (show)

See Also:


Attachments
Alternate ssh-copy-id script (1.55 KB, text/plain)
2013-07-16 06:35 AEST, Justin Garrison
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Justin Garrison 2013-07-16 05:47:21 AEST
When running ssh-copy-id, the script doesn't do any checking to see if the public key already exists in the remote authorized_keys file. If the script is run multiple times (on purpose or by accident) the file not only gets cluttered but also can get quite large if key distribution is set to run via cron.
Comment 1 Justin Garrison 2013-07-16 06:35:31 AEST
Created attachment 2317 [details]
Alternate ssh-copy-id script

I added the following check to to ssh-copy-id script from my Linux Mint 15 (OpenSSH 6.1p1) machine.

grep -f ~/.ssh/authorized_keys > /dev/null 2>&1; ! [ -a ~/.ssh/authorized_keys ] || [ $? -ne 0 ] && 

(please view the attached file for context)

I also verified that the modified section was the same on RHEL 6.4 (OpenSSH 5.3) and Fedora 14 (OpenSSH 5.5p1) but could not verify the file contents from the latest OpenSSH package. I am assuming the line is the same in the latest version.

This test will check if the public key contents already exists in the authorized_keys file or if the authorized_keys file does not exist. If the public key is already in the file or it does not exist then the public key contents will be appended to the file (and create it if necessary).
Comment 2 Philip Hands 2015-11-26 09:32:19 AEDT
The updated ssh-copy-id that has been included since openssh-6.2 now does
check for already installed keys
Comment 3 Damien Miller 2016-08-02 10:41:55 AEST
Close all resolved bugs after 7.3p1 release