在 Windows 上使用带有 SSH 密钥的 git [英] Using git with SSH-key on Windows

查看:45
本文介绍了在 Windows 上使用带有 SSH 密钥的 git的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我像这样使用 ssh 连接到我的虚拟机:

I am connecting to my virtual machine with ssh like this:

ssh -i keyfile.key user@server.com

我在要推送到的服务器上创建了一个 git 存储库,但我不知道应该如何将 keyfile.key 与 git 一起使用.

I have created a git repository on the server which I want to push to, but I do nott know how I should use the keyfile.key with git.

我应该执行命令:

git push live master

但我收到错误权限被拒绝(公钥)",那么我该如何指定密钥?我使用的是 Windows 8.

But I getting the error "permission denied (publickey)", so how do I specify the key? I am on Windows 8.

推荐答案

您需要:

  • use a, ~/.ssh/config (check where %HOME% is set, since you are on Windows).
    The config file would look like (replace <hostkey> by any string you want)

Host <hostkey>
  HostName myserver
  User user
  IdentityFile C:\path\to\.ssh\keyfile.key
  IdentitiesOnly yes

  • 使用配置主机键将您的远程 url 更改为 1

  • change your remote url to one using the config Host key

    git rmeote set-url list <hostkey>:myrepo
    

  • 这篇关于在 Windows 上使用带有 SSH 密钥的 git的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆