Skip to content

Instantly share code, notes, and snippets.

@Atalanta
Created June 11, 2011 09:04
Show Gist options
  • Save Atalanta/1020391 to your computer and use it in GitHub Desktop.
Save Atalanta/1020391 to your computer and use it in GitHub Desktop.
require 'tempfile'
def check_authorized_keys(keyfile)
@found_ssh = false
File.foreach(keyfile) do |line|
if line =~ /^ssh/
@found_ssh = true
Tempfile.open('key') do |keyfile|
keyfile.write(line)
keyfile.flush
result = %x[echo #{keyfile.path} | ssh-keygen -l 2>&1]
if result =~ /not a public key/
keyfile.unlink
return false
break
end
keyfile.unlink
end
end
end
return @found_ssh
end
p "CHECKING BAD"
p check_authorized_keys('/tmp/testkeyfile')
p "CHECKING GOOD"
p check_authorized_keys('/home/stephen/.ssh/authorized_keys')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment