我创建了一个Docker容器,并通过包含以下执行的Shell脚本来运行它:
docker run --rm -it \
--user $(id -u):$(id -g) \
--network host \
-e USER=$USER \
-e HOME=$HOME \
-h $HOSTNAME \
-v /tmp:/tmp \
-v /home/$USER:/home/$USER \
-v ~/.ssh:/home/$USER/.ssh:ro \
-e USERNAME=$USERNAME \
-w /home/$USER \
$IMAGE_NAME \
/bin/bash
因此,我认为既没有正确访问的问题,也没有关键存在的问题。但是,如果我进入之前使用ssh克隆的git工作目录,我无法进行身份验证。
git pull -v
git@mygitlab.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
打印出 ssh -tv git@mygitlab.com
命令的输出结果后,我看到了以下不同之处:
没有 Docker 容器
...
debug1: Will attempt key: /home/xxx/.ssh/id_ed25519 ED25519 SHA256:20AHxx agent
debug1: Will attempt key: gitlab ED25519 SHA256:fEqoFK agent
debug1: SSH2_MSG_EXT_INFO received
....
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/xxx/.ssh/id_ed25519 ED25519 SHA256:20AHxx agent
debug1: Authentications that can continue: publickey
debug1: Offering public key: gitlab ED25519 SHA256:fEqoFK agent
debug1: Server accepts key: gitlab ED25519 SHA256:fEqoFK agent
debug1: Authentication succeeded (publickey).
在Docker容器中:
...
debug1: Will attempt key: /home/xxx/.ssh/id_ed25519 ED25519 SHA256:20AHxx
debug1: Will attempt key: /home/xxx/.ssh/id_xmss
debug1: SSH2_MSG_EXT_INFO received
...
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/xxx/.ssh/id_rsa
debug1: Offering public key: /home/xxx/.ssh/id_ed25519 ED25519 SHA256:20AHxx
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/xxx/.ssh/id_xmss
debug1: No more authentication methods to try.
git@mygitlab.com: Permission denied (publickey).
我需要与ssh-agent有关的东西吗?
ssh-agent
。 - fredrikssh -Tv
。-T
表示“不要使用 tty”;而-t
则表示“要求使用 tty”,这是行不通的(但仍然可以获取您关心的信息,因此这就是为什么这很微不足道)。 - torek/home/me/.ssh/
文件与主机版本的/home/me/.ssh/
文件不同。在这种情况下,他直接传输了/home/me
,所以这不是问题...但他没有SSH代理文件。 - torek$SSH_AUTH_SOCK
进行通信,这是一个 Unix 域套接字。我认为你需要在 Docker 实例内部启动一个中继代理,尽管由于你直接传递了很多内容,你可能只需将$SSH_AUTH_SOCK
本身传递即可(我不确定这是否有效)。 - torekgit
命令在我的主机shell上完美运行。@torek,你是对的!!将-e SSH_AUTH_SOCK=$SSH_AUTH_SOCK \
添加到我的docker run脚本中解决了这个问题。你今天是我的英雄! - ywiyogo