2 # This script helps create an automatic login with SSH
3 # without a password. By creating a rsa key pair.
9 pinged_machines = "./pinged_machines"
11 # Check SSH connection first on the remote machines!!
12 if system("bash ./test_connection.sh") then
13 # The program nmap displays a lot of rubbish
16 puts "This script helps create an automatic login with SSH"
17 puts "so that you don't have to SSH with a password in the future"
18 puts "First I need your login for the machines you wish to gain access to:"
25 # Login to the remote machines and create the ~/.ssh folder
26 # and upload the rsa key pair into the folder.
27 fp = File.open(pinged_machines)
29 if machine.include?("#") then
30 puts "Skipping #{machine}"
32 # Creating ~/.ssh folder on the remote machines
33 puts "Creating .ssh folder on #{machine}"
34 Net::SSH.start( machine.chomp, user, :password => pass ) do |session|
35 error = session.exec!("mkdir -p ~/.ssh")
36 status = session.exec!("echo $?")
43 if status.chomp == '0' then
44 # Create the rsa key pair
45 system('ssh-keygen -t rsa')
48 system('bash upload_rsa.sh')
49 puts "Done! Now SSH into the machines and try if you can login without entering"
50 puts "a password! By doing: ssh some_user_name@some_host"
53 puts "Opps! There seems to be some problems with #{machine}"
54 puts "Error: #{error}"
59 puts "IMPORTANT NOTE!!:"
60 puts "If this small script does not work, depending on your version of SSH"
61 puts "you might have to do the following"
62 puts "- Put the public key in '.ssh/auhtorized_keys2'"
63 puts "- Change the permission of .ssh to 700"
64 puts "- Change the permission of .ssh/authorized_keys2 to 640"