2、ssh-keygen -t [rsa|dsa],将会在~/.ssh下生成密钥文件和私钥文件 id_rsa,id_rsa.pub或id_dsa,id_dsa.pub
3、将 .pub 文件复制到B机器的 .ssh 目录, 并 cat id_dsa.pub >>~/.ssh/authorized_keys
4、大功告成,从A机器登录B机器的目标账户,不再需要密码了(直接运行 #ssh 192.168.1.100 )
面交互输入,就得使用expect脚本,例:
#!/bin/bash
passwd='123456'
/usr/bin/expect <<-EOF
set time 30
spawn ssh root@192.168.1.100
expect {
"*yes/no" { send "yes\r"exp_continue }
"*password:" { send "$passwd\r" }
}
expect "*#"
send "cd /home/trunk\r"
expect "*#"
send "ls\r"
expect "*#"
send "exit\r"
interact
expect eof
EOF
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)