分类: LINUX
2011-06-16 18:46:23
$ ssh-keygen |
$ ssh-cody-id -i /root/.ssh/id_rsa user@remotehost |
$ ssh user@remotehost echo "it works" |
例:三服务器A.B.C 假设A.C要互相访问需经过B,本实现A与C之间的互访。A.B.C密码分别为:PWDA.PWDB.PWDC。操作主机为A。
1.从A到C的自动SSH登陆。
#!/usr/bin/expect -f
set timeout 30
spawn ssh
expect "password:"
send "PWDB\r"
expect "]*"
send "ssh "
expect "password:"
send "PWDC"
interact
2.从A到C文件的SCP。
#!/usr/bin/expect -f
set timeout 300
set file [lindex $argv 0]
spawn scp $file
expect "password:"
send "PWDB\r"
expect "]*"
spawn ssh
expect "password:"
send "PWDB\r"
expect "]*"
send "scp $file "
expect "password:"
send "PWDC\r"
expect "]*"
exit
interact
3.从C到A文件的SCP。
#!/usr/bin/expect -f
set timeout 300
set file [lindex $argv 0]
spawn ssh
expect "password:"
send "PWDB\r"
expect "]*"
send "scp ./\r"
expect "password:"
send "PWDC\r"
expect "]*"
send "exit\r"
expect "]*"
spawn scp ./
expect "password:"
send "PWDB\r"
interact