I'm using this command on Server1
~# ssh root@Server2 /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
to append the contents of Server2's id_rsa.pub
to the authorized_keys
of Server1.
It works if I do it manually but when I do it in an expect script:
#!/usr/bin/expect
set timeout 60
spawn ssh root@[lindex $argv 0] cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
expect "yes/no" { send "yes\r"
expect "*?assword" { send "[lindex $argv 1]\r" }
} "*?assword" { send "[lindex $argv 1]\r" }
interact
What happens when I use the script is that the id_rsa.pub
of Server2 is appended over the authorized_keys
of Server2.
What would be the correct syntax?