You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
633 B

# Find duplicate keys in ~/.ssh/known_hosts
# Of course, we should have been more careful in the first place :)
from __future__ import division, print_function
from collections import defaultdict
import os.path
import re
hostnames_per_key = defaultdict(list)
with open(os.path.expanduser('~/.ssh/known_hosts')) as f:
for line in f:
m = re.match(r'(\S+)\s+(\S+\s+\S+)(.*)?', line)
if m:
(hostname, key, cruft) = m.groups()
for key, hostnames in hostnames_per_key.items():
if len(hostnames) > 1: