I'm connecting from one remote machine to many remote machines within one network. Username and password for all remote machines is the same. I want to write a script that will use my username and pass to login to machine. I can't install any tool on host machine (expect or sshpass). Copying public key to target remote machine doesn't make a sense since I rarely connect more than once to the same machine. Everyday - new machines.
Is it possible to set up ssh on host machine to be able to connect to remote machines without need to set something on target machines?
Local machine that I'm using to connect to the rest of the network - SUSE Linux Enterprise Server 11 SP3
Given the requirements I would install expect
on my local machine and use it to add in effect a new command. Let us call the remote hosts one
and many1
, many2
and the local machine mybox
. Something like this (untested)
#!/usr/bin/expect
# connect to "one"
spawn ssh username@one
# next lines shouldn't be needed, should have shared keys for "one"
expect "assword: "
# provide password for "one", ending with "\r"
send -- "the_password_for_username@one\r"
# mainloop
interact "~p" {
send "ssh manyuser@[lindex $argv 0]\r"
expect "yes/no)? " { send "yes\r" exp_continue } "assword: "
send "the_password_for_many\r"
}
Run this on mybox
as ./script many1
, it will connect you to one
Then when you want to connect to many1
just type ~p
. It will run the ssh command, answer the "do you want to connect" question if asked, and provide the password.
Of course the standard comments about the insecurity of storing passwords in scripts apply. The other slight downside is that you need to dedicate a key sequence to this. Here I am using ~p
but you could use a function key.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments