3 # this fact will iterate over all the known users (as defined by the
4 # Etc module) and look in their .ssh directory for public keys. the
5 # public keys are exported in a user => [keys] hash, where keys are
6 # stored in the array without distinction of type
7 Facter.add(:ssh_keys_users) do
12 Dir.glob(File.join(user.dir, '.ssh', '*.pub')).each { |filepath|
13 if FileTest.file?(filepath)
14 regex = %r{^ssh-(\S+) (\S+)\s?(.+)?$}
16 line = File.open(filepath).read.chomp
17 if (match = regex.match(line))
18 keys[File.basename(filepath)] = {
21 'comment' => match[3],
26 puts "cannot read user SSH key: " + user.name
30 keys_hash[user.name] = keys if not keys.empty?