无需密码执行 rsync 命令:使用 SSH 密钥认证
要在 rsync 命令执行时不用输入密码,可以使用 SSH 密钥认证。以下是步骤:
- 生成 SSH 密钥对:使用 ssh-keygen 命令生成 SSH 密钥对。输入以下命令:
ssh-keygen -t rsa
- 将公钥复制到远程服务器:使用 ssh-copy-id 命令将公钥复制到远程服务器。输入以下命令:
ssh-copy-id username@remote_host
其中,username 是远程服务器的用户名,remote_host 是远程服务器的 IP 地址或域名。
- 测试 SSH 连接:输入以下命令测试 SSH 连接是否成功:
ssh username@remote_host
如果成功连接,将不需要输入密码。
- 使用 rsync 命令:使用 rsync 命令时,加上以下参数:
rsync -avz -e 'ssh' /local/path/ username@remote_host:/remote/path/
其中,-e 'ssh' 表示使用 SSH 协议进行传输,/local/path/ 是本地路径,username 是远程服务器的用户名,remote_host 是远程服务器的 IP 地址或域名,/remote/path/ 是远程路径。
执行 rsync 命令时,将不需要输入密码。
原文地址: https://www.cveoy.top/t/topic/kC2P 著作权归作者所有。请勿转载和采集!