Git 克隆私有仓库,权限被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14028237/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git clone private repo, permission denied
提问by user1071182
I am trying to clone a private repository owned by another developer. I do not have direct communication with this developer. They sent me a theirusername-id_rsa.pub file and a theirusername-priv.key.ppk file. I understand the ppk file is specific to to Putty ssh client. Can someone provide me with steps on how to clone their repo? I already have git configured with my own account and I think I have to add their ssh key to my ssh/config file or something, but I'm a bit of an ssh noob.
我正在尝试克隆另一个开发人员拥有的私有存储库。我与此开发人员没有直接联系。他们给我发送了一个 theirusername-id_rsa.pub 文件和一个 theirusername-priv.key.ppk 文件。我知道 ppk 文件特定于 Putty ssh 客户端。有人可以向我提供有关如何克隆他们的 repo 的步骤吗?我已经用我自己的帐户配置了 git,我想我必须将他们的 ssh 密钥添加到我的 ssh/config 文件或其他东西中,但我有点像 ssh noob。
git clone [email protected]:theirusername/pro.git
Cloning into 'pro'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Edit: I was able to get access to the github repository and add myself as a collaborator. Even after doing so I couldn't
编辑:我能够访问 github 存储库并将自己添加为合作者。即使在这样做之后我也不能
git clone [email protected]:theirusername/pro.git
however
然而
git clone https://github.com/theirusername/pro.git
did work.
没有工作。
回答by poke
They sent me a theirusername-id_rsa.pub file and a theirusername-priv.key.ppk
他们给我发送了一个 theirusername-id_rsa.pub 文件和一个 theirusername-priv.key.ppk
First of all, tell them to neverdo this. The public/private keys are called like that for a reason. It's against its point to have multiple instances (persons or computers) share the same key. You should use a separate key for every single one, to have a 1-to-1 association between them.
首先,告诉他们永远不要这样做。出于某种原因,这样调用公钥/私钥是有原因的。让多个实例(个人或计算机)共享相同的密钥是有违其意义的。您应该为每个密钥使用单独的密钥,以在它们之间建立一对一的关联。
If they can't add you as a collaborator (which would require a user account for yourself), then they should just add yourkey to their own profile. I'm emphasizing on “your key”, as youshould generate it and send them only the public key. The private one should always remain secret to everybody else.
如果他们无法将您添加为合作者(这将需要您自己的用户帐户),那么他们应该将您的密钥添加到他们自己的个人资料中。我强调“你的密钥”,因为你应该生成它并只将公钥发送给他们。私人的应该永远对其他人保密。
That being said, when you have a PPK, a PuTTY private key file, you have two options. First would be to use PuTTY's pageantto load the key file and make Git use PuTTY's plinkas the SSH client. You can do that by setting the GIT_SSH
environment variable to the path to plink.exe
, e.g. C:\Program Files\PuTTY\plink.exe
.
话虽如此,当您拥有 PPK、PuTTY 私钥文件时,您有两种选择。首先是使用 PuTTY 的pageant加载密钥文件并使 Git 使用 PuTTY 的plink作为 SSH 客户端。您可以通过将GIT_SSH
环境变量设置为 的路径来做到这一点plink.exe
,例如C:\Program Files\PuTTY\plink.exe
。
The second option would be to convert the PPK to an OpenSSH key file which the SSH client that comes with Git can use. You can do that by opening the PPK with PuTTYgen and choosing “Conversions/Export OpenSSH key”. You should save the file as C:\Users\<username>\.ssh\id_rsa
to make Git use it.
第二种选择是将 PPK 转换为 Git 附带的 SSH 客户端可以使用的 OpenSSH 密钥文件。您可以通过使用 PuTTYgen 打开 PPK 并选择“Conversions/Export OpenSSH key”来实现。您应该将文件另存为C:\Users\<username>\.ssh\id_rsa
让 Git 使用它。
回答by VonC
You need:
你需要:
- to make sure you have environment variable
HOME
defined (if you do your git operations from a git bash session, this should be defined for you even on Windows) - to convert your ppk keys into id_rsa and id_rsa.pub: see "How to I tell Git for Windows where to find my private RSA key?".
- define your config file or add your key to ssh agent, as described in "Specify private SSH-key to use when executing shell command".
- 确保您
HOME
定义了环境变量(如果您从git bash 会话执行 git 操作,即使在 Windows 上也应该为您定义) - 将您的 ppk 密钥转换为 id_rsa 和 id_rsa.pub:请参阅“如何告诉 Git for Windows 在哪里可以找到我的私有 RSA 密钥?”。
- 定义您的配置文件或将您的密钥添加到 ssh 代理,如“指定私有 SSH 密钥以在执行 shell 命令时使用”中所述。
回答by kki
Just copy and paste below code in a bat file and execute it
只需将下面的代码复制并粘贴到 bat 文件中并执行它
echo y|"C:\Program Files (x86)\PuTTY\plink.exe" [email protected] -pw XXXX exit
echo y|"C:\Program Files (x86)\PuTTY\plink.exe" [email protected] -pw XXXX exit
XXX.XXX.XXX.XXX : This is IP Address of your device.
XXX.XXX.XXX.XXX :这是您设备的 IP 地址。
XXX : This is password of your device
XXX:这是您设备的密码