Skip to content

Instantly share code, notes, and snippets.

@manveru
Forked from Atalanta/gist:1020391
Created June 11, 2011 09:23
Show Gist options
  • Save manveru/1020406 to your computer and use it in GitHub Desktop.
Save manveru/1020406 to your computer and use it in GitHub Desktop.
require 'tempfile'
def check_authorized_keys(keyfile)
valid = false
File.foreach(keyfile).map do |line|
if line =~ /^ssh/
Tempfile.open('key') do |keyfile|
keyfile.write(line)
keyfile.flush
@result = %x[echo #{keyfile.path} | ssh-keygen -l 2>&1]
keyfile.unlink
end
p @result
unless @result =~ /not a public key/
valid = true
end
end
end
return valid
end
$ ruby check-auth-keys.rb
false
"Enter file in which the key is (/home/stephen/.ssh/id_rsa): 2048 d4:67:9b:4b:ec:bf:2a:aa:a5:9f:ab:b2:0a:dc:83:cb /tmp/key20110611-19536-6qnux0 (RSA)\n"
"Enter file in which the key is (/home/stephen/.ssh/id_rsa): 2048 86:39:5f:50:ad:a6:15:36:57:99:4f:db:80:a5:8e:87 /tmp/key20110611-19536-ocnrpr (RSA)\n"
"Enter file in which the key is (/home/stephen/.ssh/id_rsa): 1024 1e:2c:4f:c4:4a:78:5d:3d:ae:90:8e:70:1f:95:92:cf /tmp/key20110611-19536-kgddwe (DSA)\n"
"Enter file in which the key is (/home/stephen/.ssh/id_rsa): /tmp/key20110611-19536-1gjh9md is not a public key file.\n"
true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment