make password-less ssh with expect

D

DKljuikov

Guest
Hello!
Im trying to write script wich will be send public ssh key to several hosts. And these actions should be executed without entering password.
i.e. i need something like:
>>>
/usr/bin/expect -c 'eval spawn {cat ~/.ssh/id_rsa.pub | ssh ftj_dklj@oracle "mkdir -p ~/.ssh && cat - >> ~/.ssh/authorized_keys"}
expect "assword:"
send "*****\n"
expect eof'
<<<
I know that pipe is not allowed in expect. Example above is just for understanding what i want) Also i've tried at least create .ssh directory. But these actions also were not successfull.

Code:
>>>
expect -c 'spawn ssh ftj_dklj@oracle
expect "assword:"{
send "****\n"
}
expect "login"{
send "mkdir -p ~/.ssh\n"
}
'
<<<
platform -
Linux oracle.test.fts 2.6.9-55.0.0.0.2.ELhugemem #1 SMP Wed May 2 15:04:06 PDT 2007 i686 i686 i386 GNU/Linux
Could u please advise what im doing wrong?
Thx, Denis
 
Last edited:


Why not try using something like sshpass or similar to do this? I take it that you want to enter your password one time and not thirty times.
 
because i have no permissions to install sshpass. But we already have expect installed. so it would be good to use that we already have
 
Issue has been fixed here is script:
Code:
#!/usr/bin/expect -f
set password "*********"
 
spawn ./ssh-copy-id.sh -i /home/oracle/.ssh/id_rsa.pub ftj_dklj@oracle
expect {
  "assword" {
    send "$password\r"
  }
}
expect eof
exit 0
But im not able to convert it to bash version.

Code:
export PASSWD="******"
 
/usr/bin/expect  << EOF
spawn ./ssh-copy-id.sh -i /home/oracle/.ssh/id_rsa.pub ftj_dklj@oracle
expect "*?assword: "
send "${PASSWD}\n"
EOF

This code is not working. Could u please correct me?
 

Staff online

Members online


Latest posts

Top