【问题标题】:force Git to create the ssh-key in the directory directory强制 Git 在目录目录中创建 ssh-key
【发布时间】:2016-09-19 08:12:36
【问题描述】:

我想将一个项目推送到 github 主页。因此,我正在尝试为 github 创建 ssh-key 来管理它,但我面临的问题是 git 在错误的目录 /c/Users/user82/.ssh/id_rsa) 而不是在项目目录 /desktop/dogs 中创建 ssh-key。

如何告诉 Git 在项目目录中也创建 ssh-key /desktop/dogs 而不是在此目录中创建 c/Users/user82?

user82@User MINGW64 ~/desktop/dogs (master)
$ ssh-keygen -t rsa -C "example@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/user82/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/user82/.ssh/id_rsa.
Your public key has been saved in /c/Users/user82/.ssh/id_rsa.pub.

【问题讨论】:

  • ssh-keygen 将密钥放在默认目录下,没有错。 Git 与此设置无关。为什么要移动项目目录中的键?您不需要将项目推送到 github。 Git 使用 ssh 客户端,ssh 客户端应该知道你的密钥的默认位置而不做任何事情。
  • 而且,无论如何,如果您想将文件放在其他位置,请自行移动?

标签: git ssh


【解决方案1】:

ssh 密钥默认保存在 $HOME 中(在 Windows 上,由 git 设置为%USERPROFILE%,即C:\Users\<yourLogin>)

ssh 将在 $HOME 中查找这些键。

如果您想拥有特定于 GitHub 帐户的密钥,您可以:

  • 使用ssh-keygen -f 在您想要的任何地方生成 ssh 密钥(或将它们从 $HOME 复制到您想要的任何地方,使用任何名称和 name.pub)
  • 在ssh config file 中引用它们,例如this one
  • 更改远程 url 以引用该 ssh 配置文件中的正确条目。

     cd / path/to/your/local/repo
     git remote set-url origin github1:username/myrepo
    

那是$HOME/.ssh/config 和:

Host github1
  HostName github.com
  User git
  IdentityFile /c/path/to/my/private/key

【讨论】:

    猜你喜欢
    • 2013-02-17
    • 2012-04-20
    • 2014-06-22
    • 2019-11-03
    • 2012-09-04
    • 1970-01-01
    • 2017-11-24
    • 2023-03-07
    • 1970-01-01
    相关资源
    最近更新 更多