大网数据广告活动
服务器运维问答

rsync not using the ssh-agent?

· 52CE 我爱测

I have this running on gitlab ci, and it works for regular ssh (copied from the gitlab ci docs): eval $(ssh-agent -s) ssh-add <(echo "$SSH_PRIVATE_KEY") mkdir -p ~/.ssh echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/co…

问题原文

原帖链接 · Sarke · CC BY-SA 4.0

I have this running on gitlab ci, and it works for regular ssh (copied from the gitlab ci docs):

eval $(ssh-agent -s)
ssh-add <(echo "$SSH_PRIVATE_KEY")
mkdir -p ~/.ssh
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config

This gives me

Identity added: /dev/fd/63 (/dev/fd/63)

However, when I try to rsync I get an error:

Warning: Permanently added '*****' (ECDSA) to the list of known hosts.
Permission denied, please try again.
Permission denied, please try again.
user@server: Permission denied (publickey,password).
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(235) [sender=3.1.3]

Why is rsync not able to use the identity added, when the ssh command is?

I can also do this instead, to work around the rsync issue.

eval $(ssh-agent -s)
mkdir -p ~/.ssh
echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-add

Which gives me

Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

Which rsync is able to use, most likely because it's in the assumed place.

Does this mean rsync uses it's own ssh implementation and not the ssh-agent on the local system?

已采纳解答

原帖链接 · saf · CC BY-SA 4.0

You can specify the ssh protocol with rsync using the "-e" option.

rsync -e ssh file.tmp example.com:~/

Identity could also be provided in that option.

rsync -e "ssh -i ~/.ssh/id_rsa" file.tmp exmple.com:~/

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-06-14)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。