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
Python
24 lines
633 B
Python
#!/usr/bin/python3
|
|
# 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()
|
|
hostnames_per_key[key].append(hostname)
|
|
|
|
for key, hostnames in hostnames_per_key.items():
|
|
if len(hostnames) > 1:
|
|
print(hostnames)
|