-
-
Save manveru/1020406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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