LMLPHP后院

rsync 结合 sshpass 实现无人值守技术

maybe yes 发表于 2022-01-14 09:58

我的运维探索又进了一步,N 多年前就知道 expect,感觉难用,语法看起来奇怪,为了实现自动化,想尽了方法,echo、管道、重定向等都不行,这第一次安装 sshpass,一次就成!

rsync -avz --append --progress -e 'sshpass -p x ssh -p 9' lmlphp:x/* .

记得修改文件权限哦!

发现 sshpass 的体积很小哦,只有 11 kb,可以了解下实现原理!

11.23 分享一个重要的命令,结合跳板机:

env SSHPASS="password" rsync -avz --append --progress -e "sshpass -d 123 ssh -p 22 -o ProxyCommand=\"sshpass -e ssh -p 22 -W %h:%p root@jumper\" root@dest" :bak/* /home/local/ 123<<<password

上面的命令我一直没有测试成功,折腾了很久,拧巴了一上午,最后发现,是因为我从来没有连接过 jumper,所以导致了下面的错误:

ssh_exchange_identification: Connection closed by remote host
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: unexplained error (code 255) at io.c(235) [Receiver=3.1.3]

解决的办法,当然是,连接一次啦。

The authenticity of host '[jumper]:22 ([jumper]:22)' can't be established.
ECDSA key fingerprint is SHA256:GLBRd/x+GU.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[jumper]:22' (ECDSA) to the list of known hosts.

SSHPASS 定义的是 jumper 的 password。

2024-11-22 00:06:51 1732205211 0.006719