Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 生成Docker映像时无法使用私钥进行SSH_Git_Ssh_Docker_Openssh - Fatal编程技术网

Git 生成Docker映像时无法使用私钥进行SSH

Git 生成Docker映像时无法使用私钥进行SSH,git,ssh,docker,openssh,Git,Ssh,Docker,Openssh,在Docker映像构建期间,我无法签出GitHub上托管的私有git存储库。详细模式下SSH的错误为: OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: Applying options for * debug1: Connecting to github.com [192.30.2

在Docker映像构建期间,我无法签出GitHub上托管的私有git存储库。详细模式下SSH的错误为:

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [192.30.252.130] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
debug1: no match: libssh-0.6.0
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
debug1: read_passphrase: can't open /dev/tty: No such device or address
Host key verification failed.
/dev/tty
设备似乎确实存在:

total 4
drwxr-xr-x   4 root root     340 Jul 22 17:12 .
drwxr-xr-x 130 root root    4096 Jul 22 17:12 ..
lrwxrwxrwx   1 root root      13 Jul 22 17:12 fd -> /proc/self/fd
crw-rw-rw-   1 root root  1,   7 Jul 22 17:12 full
c---------   1 root root 10, 229 Jul 22 17:12 fuse
lrwxrwxrwx   1 root root      11 Jul 22 17:12 kcore -> /proc/kcore
crw-rw-rw-   1 root root  1,   3 Jul 22 17:12 null
lrwxrwxrwx   1 root root       8 Jul 22 17:12 ptmx -> pts/ptmx
drwxr-xr-x   2 root root       0 Jul 22 17:12 pts
crw-rw-rw-   1 root root  1,   8 Jul 22 17:12 random
drwxrwxrwt   2 root root      40 Jul 22 17:12 shm
lrwxrwxrwx   1 root root      15 Jul 22 17:12 stderr -> /proc/self/fd/2
lrwxrwxrwx   1 root root      15 Jul 22 17:12 stdin -> /proc/self/fd/0
lrwxrwxrwx   1 root root      15 Jul 22 17:12 stdout -> /proc/self/fd/1
crw-rw-rw-   1 root root  5,   0 Jul 22 17:12 tty
crw-rw-rw-   1 root root  1,   9 Jul 22 17:12 urandom
crw-rw-rw-   1 root root  1,   5 Jul 22 17:12 zero
下面是我的
Dockerfile
的精简版本,演示了我的测试:

FROM ubuntu:trusty

ADD . /my_app
ADD ./config/ssh/docker_ssh_key /root/.ssh/id_rsa

RUN ls -al /dev
RUN ssh -t -t -v git@github.com

CMD bundle exec thin -p $PORT -R config.ru start
我已经测试了这个构建,并且知道这个键确实有效。如果我在不使用RUN命令的情况下构建映像并使用交互式shell启动容器,那么我可以很好地访问git存储库


我还发现了其他一些类似错误消息的问题。但是它们是为了缺少
/dev/tty
,而这里似乎不是这样。有什么想法吗?

您需要接受Github主机密钥。使用ssh密钥扫描:

ssh-keyscan -t rsa github.com 2>&1 >> /root/.ssh/known_hosts

私钥(在客户端或服务器上)是否有密码短语?如果是这样,也许可以尝试一个测试,看看使用未加密的私钥是否会导致相同的问题。这不是最安全的设置,但它可能会帮助您隔离问题。谢谢!我最终认为是接受主机密钥的提示出现了。手动接受会抑制此提示,SSH将继续。谢谢。需要在容器docker中实现git克隆,而无需复制~/.ssh/know_主机。您还可以禁用密钥检查: