使用crontab出现Host key verification failed的问题

发布时间:2024-01-08 点击:137
假如我们现在有这样两台服务器,都用root登陆。
服务器1:vm01
服务器2:vm02
如何在vm01服务器中免密码登陆登陆vm02?我们使用ssh-keygen认证的方法。比如在ubuntu系统vm01服务器上,我们就可以用下面两个命令简单配置来实现。
ssh-keygen -t rsa -n \'\'ssh-copy-id root@vm02按照这个设置后,使用securecrt登陆服务器vm01,ssh测试登陆vm02成功。但是博主今天碰到一个奇怪的问题,在vm01中用crontab计划运行脚本传文件到vm02的时候出现了错误,log信息提示“host key verification failed.” 。
为了找到具体错误原因,需要看下详细登陆信息,在脚本中添加ssh -vvv root@vm02,看是否可以登陆。最后找到错误如下:
openssh_4.3p2, openssl 0.9.8e-fips-rhel5 01 jul 2008pseudo-terminal will not be allocated because stdin is not a terminal.debug1: reading configuration data /etc/ssh/ssh_configdebug1: applying options for *debug2: ssh_connect: needpriv 0debug1: connecting to vm02[xxx.xxx.xxx.xxx] port 22.debug1: connection established.debug1: permanently_set_uid: 0/0...中间省略...debug2: kex_parse_kexinit:debug2: kex_parse_kexinit:debug2: kex_parse_kexinit: first_kex_follows 0debug2: kex_parse_kexinit: reserved 0debug2: mac_init: found hmac-md5debug1: kex: server->client aes128-cbc hmac-md5 nonedebug2: mac_init: found hmac-md5debug1: kex: client->server aes128-cbc hmac-md5 nonedebug1: ssh2_msg_kex_dh_gex_request(1024<1024<8192) sentdebug1: expecting ssh2_msg_kex_dh_gex_groupdebug2: dh_gen_key: priv key bits set: 135/256debug2: bits set: 513/1024debug1: ssh2_msg_kex_dh_gex_init sentdebug1: expecting ssh2_msg_kex_dh_gex_replydebug3: check_host_in_hostfile: filename /root/.ssh/known_hostsdebug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hostsdebug3: check_host_in_hostfile: filename /root/.ssh/known_hostsdebug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hostsdebug3: check_host_in_hostfile: filename /root/.ssh/known_hostsdebug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hostsdebug2: no key of type 0 for host masterdebug3: check_host_in_hostfile: filename /root/.ssh/known_hosts2debug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hosts2debug3: check_host_in_hostfile: filename /root/.ssh/known_hostsdebug3: check_host_in_hostfile: filename /etc/ssh/ssh_known_hostsdebug2: no key of type 2 for host masterdebug1: read_passphrase: can\'t open /dev/tty: no such device or address<strong>host key verification failed.</strong>从上面log中可以看到主要是这个错误,“debug1: read_passphrase: can’t open /dev/tty: no such device or address” 。因为crontab里的脚本不带任何用户定义的环境变量,所以最好在脚本开头调用一下这些变量。
博主就用env命令看了下当前成功登陆vm01系统的环境变量,然后把这些变量放到脚本开头就解决问题了。。。


网站怎么做百度排名与转化率的SEO优化?
云服务器建站价格对比图
云计算核心技术Docker教程:利用Dockerfile来创建镜像
最新版Linux7.0系统宝塔面板安装教程
这个让你们修改为一样的了为啥提交不了帮忙看下
word文档标题怎么设置 word文档设置标题样式的方法
这个香港服务器链接不了远程
云有个服务器挺划算