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 [email protected]
[email protected]: 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,[email protected]
#   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 (将#修改为@)