简体   繁体   English

将Git(Windows)与私钥一起使用

[英]Use Git (Windows) with a private key

I have a Git repository on a Linux server and I want to clone it on Windows. 我在Linux服务器上有一个Git存储库,我想在Windows上克隆它。

I have Git for Windows installed and I prefer using it with the command line. 我已经安装了Windows版Git,我更喜欢在命令行中使用它。

I use SSH with a public key to connect to my Linux server and I have my keys generated and ready to use, but I don't know how to tell git to use the key. 我使用带有公共密钥的SSH连接到我的Linux服务器,并且已经生成了密钥并可以使用,但是我不知道如何告诉git使用密钥。

When I just SSH into the box, I use this command: 当我仅将SSH插入框中时,我使用以下命令:

ssh -i c:\path\to\private\key\id_rsa user@192.168.2.104

So, I guess I'm looking for Git's equivalent of the -i option. 因此,我猜我在寻找与-i选项等效的Git。

Obviously, this doesn't work: 显然,这不起作用:

git -i c:\path\to\private\key\id_rsa clone user@192.168.2.104:/home/user/dev/myproject.git myproject

This is all on my local network. 这些都在我的本地网络上。

On Windows, provided %HOME% is set to %USERPROFILE% , use a %HOME%\\.ssh\\config file, which can indicate, for a given entry name, the user and the path of the private key: 在Windows上,将%HOME%设置为%USERPROFILE% ,请使用%HOME%\\.ssh\\config文件,该文件可以为给定的条目名称指示用户私钥的路径:

Host yourServer
  HostName 192.168.2.104
  User user
  IdentityFile C:/path/to/yourPrivateKey

Test it with ssh -Tv yourServer ssh -Tv yourServer测试

Then a clone would be: 那么克隆将是:

git clone yourServer:/home/user/dev/myproject.git myproject

(no need to indicate user@192.168.2.104 or the path to the private key anymore: everything is in the %HOME%/.ssh/config ) (不再需要指出user@192.168.2.104或私钥的路径:一切都在%HOME%/.ssh/config

That way, you can manage multiple ssh sets of public/private keys. 这样,您可以管理多个ssh组公钥/私钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM