首页 > 解决方案 > 在 Windows 上使用 SSH 私钥进行 Git 推送

问题描述

在这些命令之后,

git remote add origin server:<repo>.git
git push origin master

我需要输入密码。但我只想使用我的私有 ssh 密钥对服务器进行身份验证。例如,我可以使用该私钥连接到服务器,但我不知道如何使用它推送 git 存储库。

我的公钥 ofc 被添加到服务器上的授权密钥中。

标签: gitsshssh-keys

解决方案


Your server need to support ssh or gitosis in order to do it. Gitosis:

In your cae you mentioned that you do have ssh connection so you simply have to set the remote with the ssh protocol

git remote set-url origin ssh://......

# or
git remote set-url origin git@...

how to configure ssh key path for git

  • Open a terminal window.
  • Edit the ~/.ssh/config file.
  • If you don't have a config file, create one.
  • Add an alias for each identity combination for example:

    Host <Host Name>
    HostName AAAAAAA.org
    IdentityFile ~/.ssh/<key for the given host>
    
    Host <Host1 Name>
    HostName BBBBB.org
    IdentityFile ~/.ssh/<host 2 key>
    

推荐阅读