Last active
December 17, 2015 18:09
-
-
Save ashrithr/5651057 to your computer and use it in GitHub Desktop.
ruby function to check if passwordless is setup
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
def sshable?(nodes_arr, ssh_user, ssh_key, port=22) | |
nodes_arr.each do |instance| | |
`ssh -t -t -o ConnectTimeout=2 -o StrictHostKeyChecking=no -o BatchMode=yes -i #{ssh_key} #{ssh_user}@#{instance} "echo" &>/dev/null` | |
#ssh options used: | |
#ConnectTimeout => timeout the ssh session | |
#StrictHostKeyChecking => dont check for host key | |
#BatchMode => dont ask for password, of prompted for password exit out | |
#-t -t => Force pseudo-tty allocation, Multiple -t options force tty allocation, even if ssh has no local tty | |
unless $?.success? | |
puts "[Error]: cannot ssh into instance: #{instance}" | |
exit 1 | |
end | |
end | |
end | |
#Usage: | |
nodes = %w(localhost 127.0.0.1) | |
sshable(nodes, 'root', '~/.ssh/id_rsa') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment