【问题标题】:Cannot "git clone" from local host无法从本地主机“git clone”
【发布时间】:2018-04-22 10:20:33
【问题描述】:

两台安装了 ubuntu 的笔记本电脑。

这些系统上 user1 的 ssh 和 git config 设置相同。

cat /home/user1/.ssh/config
Host system1
        Hostname <system1_ip>
        User user1
        IdentityFile ~/.ssh/id_rsa_common

cat /home/user1/.gitconfig
[user]
        email = user1@gmail.com
        name = user1

Rsa 私钥/公钥在这些系统中也是相同的

user1@system1:~/.ssh$ ls -al
total 28
drwx------  2 user1 user1 4096 Apr 18 00:09 .
drwxr-xr-x 50 user1 user1 4096 Apr 18 00:06 ..
-rw-------  1 user1 user1  408 Feb 18  2017 authorized_keys
-rw-rw-r--  1 user1 user1   91 Apr 18 00:04 config
-r--------  1 user1 user1 1675 Feb 24  2017 id_rsa_common
-rw-r--r--  1 user1 user1  408 Feb 24  2017 id_rsa_common.pub
-rw-r--r--  1 user1 user1 1550 Apr 12 19:51 known_hosts


user1@system2:~/.ssh$ ls -al
total 24
drwxrwxr-x  2 user1 user1 4096 Apr 17 20:12 .
drwxr-xr-x 21 user1 user1 4096 Apr 17 23:08 ..
-rw-rw-r--  1 user1 user1   91 Apr 17 20:12 config
-r--------  1 user1 user1 1675 Apr 17 20:12 id_rsa_common
-rw-r--r--  1 user1 user1  408 Apr 17 20:12 id_rsa_common.pub
-rw-r--r--  1 user1 user1 1550 Apr 17 20:12 known_hosts

在 system1 中创建的 git 存储库。

user1@system2 可以正确执行“git clone”

user1@system2:~/job/test$ git clone ssh://<system1_ip>/home/git_root/mypicture.git
Cloning into 'mypicture'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
orion@ubuntu-pavilion:~/job/test$ ls -al mypicture/
total 12
drwxrwxr-x 3 user1 user1 4096 Apr 18 01:38 .
drwxrwxr-x 3 user1 user1 4096 Apr 18 01:38 ..
drwxrwxr-x 7 user1 user1 4096 Apr 18 01:38 .git

user1@system1 尝试“git clone”

响应是 Permission denied (publickey)。

user1@system1:~/job/git_test/local/temp$ git clone ssh://<system1_ip>/home/git_root/mypicture.git
Cloning into 'mypicture'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

用这个命令调试:

GIT_SSH_COMMAND="ssh -vvv" git clone ssh://system1_ip/home/git_root/mypicture.git

部分转储显示找不到私钥:

...
debug1: SSH2_MSG_NEWKEYS received
debug2: key: /home/user1/.ssh/id_rsa ((nil))
debug2: key: /home/user1/.ssh/id_dsa ((nil))
debug2: key: /home/user1/.ssh/id_ecdsa ((nil))
debug2: key: /home/user1/.ssh/id_ed25519 ((nil))
....
debug1: Trying private key: /home/user1/.ssh/id_rsa
debug3: no such identity: /home/user1/.ssh/id_rsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_dsa
debug3: no such identity: /home/user1/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ecdsa
debug3: no such identity: /home/user1/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/user1/.ssh/id_ed25519
debug3: no such identity: /home/user1/.ssh/id_ed25519: No such file or directory

如何将 user1@system1 的 ssh/git 配置或其他配置更改为在 system1 上“git clone”此存储库?

【问题讨论】:

  • .ssh 目录的权限是什么?
  • 07000775 分别。显然。这实际上包含在问题中。从这个意义上说,这是我希望看到问题的 system2。不过,config 烫发可能太多了。

标签: git ssh


【解决方案1】:

我冒昧地猜测,过于宽松的${HOME}/.ssh/config 会影响您的 ssh,请尝试将其限制为 0600。查看详细输出,它会尝试使用默认键名,而不是您指定的 ~/.ssh/id_rsa_common

您也可以更正系统二上的权限。通常$HOME/.ssh/ 将是0700config 和键以及known_hostsauthorized_hosts 将是0600

但是,这只是基于可用信息的猜测。有一件事让我感到震惊(但可能是 *buntu 特定的),我的 ssh 会拒绝 ${HOME}/.ssh/config 并在您的系统上看到许可,但它也会让我知道它在控制台上使用 Bad owner or permissions on /home/user1/.ssh/config 这样做。

希望这会有所帮助。

【讨论】:

    【解决方案2】:

    尝试以下方法:

    将密钥添加到 ssh:

    ssh-add
    

    这将添加默认密钥,除非您提供要添加的特定密钥

    ssh-add 是一个命令,用于将 SSH 私钥添加到 SSH 身份验证代理中,以使用 SSH 实现单点登录。代理进程称为ssh-agent

    阅读下文,了解如何运行它。

    启动/重启 ssh=agent

    eval $(ssh-agent)
    

    这将启动 ssh 代理并打印出服务的 PID。

    ssh-agent 是一个helper 程序,用于跟踪用户的身份密钥及其密码。然后,代理可以使用密钥登录其他服务器,而无需用户再次输入密码或密码。

    【讨论】:

    • 感谢您的建议! eval ssh-agent -s ssh-add ~/.ssh/id_rsa_common 我猜 user1@system1 会将此密钥用于任何 ssh 遥控器。
    【解决方案3】:

    根本原因是 user1@system1 在执行git clone 时无法识别ssh://system1_ip

    ${HOME}/.ssh/config 只指定Host system1 中的密钥,而不是Host system1_ip

    所以如果user1@system1申请ssh://system1就可以正常工作

    但到目前为止,我不知道为什么 user1@system2 可以指定密钥 if ssh://system1_ip

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2019-11-24
      • 2011-12-14
      • 2019-09-16
      • 2013-08-19
      • 1970-01-01
      • 2016-09-30
      相关资源
      最近更新 更多