Chinaunix

标题: 求助:scp自动传入密码和公钥 [打印本页]

作者: lxh9090    时间: 2015-03-18 15:38
标题: 求助:scp自动传入密码和公钥
本帖最后由 lxh9090 于 2015-03-18 16:08 编辑

#! /usr/bin/expect -f
spawn scp -P 端口 root@x.x.x.x:/x.txt /x.txt
expect "*password:"
send "12345\r"
expect eof

-----
以上脚本可以在scp的时候自动传入密码12345,但是有一种情况是比如我这个机器第一次连接x.x.x.x去scp东西的时候需要从对方下载RSA key(公钥)
The authenticity of host '[x.x.x.x]:端口 ([x.x.x.x]:端口)' can't be established.
RSA key fingerprint is 5e:23:13:55:0d:70:74:fe:3a:d8:5c:79:33:e7:c3:ce.
Are you sure you want to continue connecting (yes/no)?
也就是没有对方公钥的时候自动传入yes,然后再传入密码,已经有对方公钥的情况下直接传入密码
作者: l08375047    时间: 2015-03-18 17:17
本帖最后由 l08375047 于 2015-03-18 17:18 编辑

#! /usr/bin/expect -f
spawn scp -P 端口 root@x.x.x.x:/x.txt /x.txt

expect {
"(yes/no)?"
{
send  "yes\n"
expect "*password:"  { send  "12345\n" }
}
"*password:"
{
send "12345\n"
}
}
expect eof
作者: 我是一隻羊    时间: 2015-03-18 17:49
  1. /etc/ssh/ssh_config
  2. StrictHostKeyChecking yes
复制代码
改成
  1. StrictHostKeyChecking no
复制代码

作者: lxh9090    时间: 2015-03-19 09:07
本帖最后由 lxh9090 于 2015-03-19 09:09 编辑

回复 2# l08375047

非常感谢!


   




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2