Last active
July 29, 2020 23:13
-
-
Save jjam3774/8215683 to your computer and use it in GitHub Desktop.
A Utility that will allow you to create and copy authentication keys to your remote servers.
This file contains 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
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'pty' | |
require 'expect' | |
require 'highline/import' | |
module SSHKeyUtil | |
$expect_verbose = true | |
$VERBOSE=true | |
def self.create_key | |
puts "Preparing to create key to transfer to remote systems..." | |
PTY.spawn('ssh-keygen -t rsa') { |rscreen, wscreen, pid| | |
rscreen.expect(/Enter/) | |
wscreen.puts("") | |
rscreen.expect(/Enter/) | |
wscreen.puts("") | |
rscreen.expect(/Enter/) | |
wscreen.puts("") | |
} | |
end | |
def self.copy_key | |
puts "LDAP Userid: " | |
user = gets | |
pass = ask("Enter your password: ") { |q| q.echo = "*" } | |
File.open('hostfile').each { |i| | |
puts "Copying key to #{i}" | |
PTY.spawn("ssh-copy-id -i #{user.chomp}@#{i.chomp}"){ |rscreen, wscreen, pid| | |
rscreen.expect(/The/) | |
wscreen.puts('yes') | |
rscreen.expect(/password/) | |
wscreen.puts(pass) | |
rscreen.expect(/[#$%]/) | |
wscreen.puts | |
} | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment