如何解决SSH 代理转发 - 连接被拒绝
我使用的是 Windows 10。使用运行 wsl2 的 docker 桌面。为了实现 ssh-agent-forwarding,我将主机的 ssh-agent 套接字安装在 docker 容器内,并在该容器内设置 SSH_AUTH_SOCK
环境变量以指向该安装的套接字。这是该容器的 docker-compose.yml 文件 -
environment:
- SSH_AUTH_SOCK=/etc/ssh/ssh_agent
volumes:
- /home/robin/.ssh/ssh_agent:/etc/ssh/ssh_agent
/home/robin/.ssh/ssh_agent
是我主机的 ssh-agent-socket。我已将我的身份密钥添加到主机的代理中,并且工作正常。
当我在构建后进入容器并尝试连接到 bitbucket 时,我收到 Permission denied (publickey).
错误。我回应了 SSH_AUTH_SOCK 变量,它指向从主机安装的套接字。我试图从容器内部列出 ssh-agent 的身份:
### entering docker container
docker exec -it b3b34c6a3317 bash
##### inside container
root@b3b34c6a3317:~# ssh -T git@bitbucket.org
git@bitbucket.org: Permission denied (publickey).
root@b3b34c6a3317:~# ssh-add -l
Error connecting to agent: Connection refused
这是主机的/etc/ssh/ssh_config
:
Host *
ForwardAgent yes
# ForwardX11 no
# ForwardX11Trusted yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# GSSAPIKeyExchange no
# GSSAPITrustDNS no
# BatchMode no
# CheckHostIP yes
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
# Protocol 2
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,umac-64@openssh.com
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p gateway.example.com
# RekeyLimit 1G 1h
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes
这里是 docker 容器的 ssh_auth_sock 值的输出:
root@b3b34c6a3317:~# echo $SSH_AUTH_SOCK
/etc/ssh/ssh_agent
不知道我哪里做错了?我是否也必须更改 docker 容器内的一些设置? 希望得到一些建议。谢谢
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。