账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    在docker里基于git的post-receive实现部署时提示`Host key verification failed`
    61
    0

    在看了很多使用git的post-receive实现部署的文章设置都很简单,但是我这里的情况相对复杂。

    1. 远端仓库使用gogs管理,而且gogs建立在docker的容器里
    2. 部署目录在主容器的/www下,挂载到gogs容器的/www下面
    3. 仓库使用ssh链接远端的
    4. gogs容器下的用户是git

    找了很大一部分解决办法说是使用ssh链接远端可以修改GIT_SSH_COMMAND指定key文件,我试过在主容器(root用户)的/www目录下创建key文件,并修改其归属为git用户,结果未能解决。

    # in git/hooks/post-receive
    
    $ ls -l /www/.ssh
    -rw-------    1 git      root          1675 Mar 20 04:17 uxfeel
    -rw-r--r--    1 git      root           392 Mar 20 04:17 uxfeel.pub
    
    $ GIT_SSH_COMMAND="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i /www/.ssh/uxfeel"
    $ cd /www/***
    $ git fetch
    
    Host key verification failed.
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

    第二个方案又再直接一些,由于gogs的容器把git用户的目录映射了出来,我就在主容器下找到映射出来的git/.ssh/目录下生成key文件,然后修改为git所属。结果还是提示Host key verification failed.

    # in git/hooks/post-receive
    
    $ ls -l ~/.ssh
    -rw-------    1 git      git           6897 Mar 20 07:01 authorized_keys
    -rw-------    1 git      git             23 Feb  9 07:26 environment
    -rw-------    1 git      root          1679 Mar 20 07:12 id_rsa
    -rw-r--r--    1 git      root           392 Mar 20 07:13 id_rsa.pub
    -rw-r--r--    1 git      git            806 Mar 20 05:37 known_hosts
    
    $ cd /www/***
    $ git fetch
    
    Host key verification failed.
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.

    到这只能放弃了。求大神搭救啊!!!

    ----------------------补充------------------------

    Host key verification failed.的出现之前写drone的插件时遇到过,当时的情况是key文件没有给相应的权限,导致插件内部用户无法访问然后git请求实际没有带上密钥。但是此处已经多次核实容器内的用户是拥有文件可读权限的。

    3
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 11 元积分
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部