如何在没有密钥的情况下通过ssh从公共仓库获取资金?

时间:2016-07-04 08:35:14

标签: git github

我有一个公共回购,https://github.com/rlpowell/config。我曾经能够在没有任何ssh密钥(即来自cron)的情况下运行git pull,并且使用git@github.com:rlpowell / config.git URL(即SSH URL)工作正常。这不再有效,我不知道为什么,但它确实为我的两个朋友工作。

我希望能够在没有ssh密钥的情况下使用公共仓库,或至少理解为什么它对我不起作用而且对其他人起作用。

这是一位朋友在尝试我的测试用例:

$ git clone git@github.com:rlpowell/config.git  ; cd config ; (unset SSH_AUTH_SOCK ; ssh-add -l ; git pull )
Cloning into 'config'...
Warning: Permanently added the RSA host key for IP address '192.30.253.113' to the list of known hosts.
remote: Counting objects: 1061, done.
remote: Total 1061 (delta 0), reused 0 (delta 0), pack-reused 1061
Receiving objects: 100% (1061/1061), 544.42 KiB | 495.00 KiB/s, done.
Resolving deltas: 100% (632/632), done.
Checking connectivity... done.
Could not open a connection to your authentication agent.
Already up-to-date.

这是我做同样的事情:

$ git clone git@github.com:rlpowell/config.git  ; cd config ; (unset SSH_AUTH_SOCK ; ssh-add -l ; git pull )
Cloning into 'config'...
remote: Counting objects: 1061, done.
remote: Total 1061 (delta 0), reused 0 (delta 0), pack-reused 1061
Receiving objects: 100% (1061/1061), 544.42 KiB | 0 bytes/s, done.
Resolving deltas: 100% (632/632), done.
Checking connectivity... done.
Could not open a connection to your authentication agent.
Enter passphrase for key '/home/rlpowell/.ssh/id_rsa':
Permission denied (publickey).
fatal: Could not read from remote repository.

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

(我在ssh密码密码提示下按Enter键。)

在repo中,.git / config是:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[remote "origin"]
        url = git@github.com:rlpowell/config.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

git config -l是:

$ git config -l
user.email=rlpowell@digitalkingdom.org
user.name=Robin Lee Powell
push.default=matching
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=git@github.com:rlpowell/config.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master

git版本是2.5.5

strace说实际运行ssh的东西是

ssh git@github.com git-upload-pack 'rlpowell/config.git'

8 个答案:

答案 0 :(得分:11)

首先尝试运行此命令:

ssh -o PreferredAuthentications=password -o PubkeyAuthentication=no github.com

然后再次git pull

答案 1 :(得分:8)

我刚刚尝试了没有密钥,我确认它无法正常工作(没有SSH密钥):

$ git clone git@github.com:rlpowell/config.git
Cloning into 'config'...
Permission denied (publickey).
fatal: Could not read from remote repository.

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

这是因为GitHub不会通过SSH授权匿名访问(而不是https),因为其他git repo服务器决定这样做(like Gogitsgo-gitea

GitHub does mention

  

SSH URL通过SSH(一种安全协议)提供对Git存储库的访问   要使用这些网址,您计算机上必须 generate an SSH keypair并将公钥添加到您的GitHub帐户。

(强调必须

Why? (asked in 2015)。虽然sshd can be configured to allow anonymous access,但没有任何公共网站会考虑设置它:它的安全风险太大。

  

需要在没有特定密钥的情况下工作

如果您需要匿名访问,可以使用:

  • https网址
  • 一个git网址:git://github.com/<user>/<repo>,虽然它使用的是端口9418,它通常在企业环境中被阻止。

答案 2 :(得分:4)

问题似乎与ssh键有关,至少响应它:

Enter passphrase for key '/home/rlpowell/.ssh/id_rsa':
Permission denied (publickey).

所以你需要将你的公钥添加到github

Adding a new SSH key to your GitHub account

您也可以运行:

ssh -T git@github.com

检查与github的ssh连接

答案 3 :(得分:4)

这是一个公共的GitHub仓库,你只想从中取出,所以你可以使用HTTPS URL:

https://github.com/rlpowell/config.git

https://github.com/rlpowell/config.git

答案 4 :(得分:2)

对于公共回购,您不需要任何密码。您可以使用他们的https链接直接克隆:

例如git clone https://github.com/rlpowell/config.git

答案 5 :(得分:1)

您的证书存在问题。 简单的解决方案就是创建一个新的并替换旧的。

问题可能是由几个问题引起的,例如:错误的主机文件输入,调用的ssh证书等等。

所以最好的办法是创建一个新证书并进行测试。

只需按照这些步骤操作即可立即设置ssh密钥:

  • 生成新的ssh密钥(如果已有密钥,则跳过此步骤)
    ActiveRecord::Schema.define(version: 20160703171518) do create_table "appointments", force: :cascade do |t| t.string "name" t.string "phone" t.string "email" t.integer "numpeople" t.date "date" t.string "timeslot" t.integer "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "appointments", ["user_id"], name: "index_appointments_on_user_id" create_table "options", force: :cascade do |t| t.decimal "pricePerPerson" t.integer "discount" t.integer "appointment_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "options", ["appointment_id"], name "index_options_on_appointment_id" create_table "profiles", force: :cascade do |t| t.string "firstname" t.string "lastname" t.text "address" t.string "email" t.string "phone" t.integer "user_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "profiles", ["user_id"], name: "index_profiles_on_user_id" create_table "users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false t.string "reset_password_token" t.datetime "reset_password_sent_at" t.datetime "remember_created_at" t.integer "sign_in_count", default: 0, null: false t.datetime "current_sign_in_at" t.datetime "last_sign_in_at" t.string "current_sign_in_ip" t.string "last_sign_in_ip" t.datetime "created_at", null: false t.datetime "updated_at", null: false end add_index "users", ["email"], name: "index_users_on_email", unique: true add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end

  • 将密钥设置在ssh-keygen -t rsa -C "your@email"目录(或Windows下的home/.ssh)后,打开它并复制内容

如何将sh键添加到github帐户?

  • 登录github帐户
  • 点击右上角的牧场主(设置)
    github account settigns
  • 点击Users/<your user>.ssh
    ssh key section
  • 点击SSH keys
    Add ssh key
  • 粘贴您的密钥并保存

你们都准备出发了: - )

答案 6 :(得分:1)

如果没有进行身份验证,无法连接到SSH服务器。

因此,如果没有注册的SSH密钥,则无法无法克隆或提取SSH。

您有两种选择:

  • 以具有与GitHub帐户关联的SSH密钥的用户身份运行cron作业(如果需要,可以使用配置文件指向特定密钥文件)。
  • 使用HTTPS。

答案 7 :(得分:1)

我认为你不能用SSH做到这一点。这是一个很好的解释:

GitHub protocol comparison

如果你想在没有任何密钥的情况下克隆和拉取东西,请使用HTTP(S)。

所以用

git clone http://github.com/rlpowell/config.git
Klone nach 'config' ...
warning: Leite nach https://github.com/rlpowell/config.git/ um
remote: Counting objects: 1234, done.
remote: Total 1234 (delta 0), reused 0 (delta 0), pack-reused 1234
Empfange Objekte: 100% (1234/1234), 2.01 MiB | 1.07 MiB/s, Fertig.
Löse Unterschiede auf: 100% (758/758), Fertig.

“.git / config”将如下所示:

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
[remote "origin"]
    url = http://github.com/rlpowell/config.git
    fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
    remote = origin
    merge = refs/heads/master

如果您已克隆或使用git config

,则可以稍后更改该文件

使用这些设置,您可以随时git pull

为什么使用网址git@github.com:rlpowell/config.git不起作用是由于以下原因:

条目git@github.com:rlpowell将强制您使用SSH进行身份验证。如果您想要SSH身份验证,Github要求您使用密钥对。

如果您想拥有一个自动cronjob用户并仍然使用SSH,请为该用户创建一个密钥对,并将公共用户上传到gitlab。

但是如果你只想克隆和拉动,那么HTTPS就足够了。顺便说一句,通过HTTPS进行验证也是可能的。如果您尝试推送更改,Github会询问您的用户名和密码。如果您使用的是cronjobs,建议不要这样做。

相关问题