How to clear duplicated entries in SSH known_hosts and authorized_keys files?

The commandline utilities are called uniq and sort. You can simply pipe the file through them to get only unique entries:

sort ~/.ssh/authorized_keys | uniq > ~/.ssh/authorized_keys.uniq

and then replace the old file with the new one:

mv ~/.ssh/authorized_keys{.uniq,}

The ~/.ssh/known_hosts are handled by ssh itself and should not contain any duplicates (if you modified it by hand, it can and then you can use the same approach as above).


ssh-keygen -R hostname will remove the entry for specified hostname

Tags:

Ssh

Openssh