简体   繁体   English

github ssh 密钥名称

[英]github ssh key names

I'm trying to configure git so I don't have to keep authenticating (and also learn a bit more about git).我正在尝试配置 git,这样我就不必继续进行身份验证(并且还要了解更多关于 git 的知识)。

I had previously been using password-based authentication, which is repetitive to keep typing in my passwords.我以前一直在使用基于密码的身份验证,这是重复输入我的密码。 I followed the steps (using windows) to set up SSH keys in github.我按照步骤(使用 Windows)在 github 中设置 SSH 密钥。 I gave my key a specific name, anticipating that I will need more than one SSH key at some point.我为我的密钥指定了一个特定的名称,预计在某些时候我将需要多个 SSH 密钥。 It doesn't make sense to always have id_rsa for github!总是为 github 提供id_rsa是没有意义的! I received the email that the key was successfully created, and I used git bash (because windows) to start the SSH client silently and added my private key.我收到了成功创建密钥的电子邮件,我使用 git bash(因为 windows)静默启动 SSH 客户端并添加了我的私钥。 But running a git clone gave me this error:但是运行git clone给了我这个错误:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

I then had the idea to try it with the default name ( id_rsa ), rather than my custom name, and of course it works.然后我想用默认名称( id_rsa )而不是我的自定义名称来尝试它,当然它可以工作。 So my question is how do I avoid this?所以我的问题是如何避免这种情况? I don't want the default name to be reserved for github.我不希望为 github 保留默认名称。

You can set up an ssh configuration file to tell the ssh command to use that specific key when connecting to github.您可以设置一个 ssh配置文件来告诉ssh命令在连接到 github 时使用该特定密钥。

Create the file .ssh/config with the content:使用以下内容创建文件.ssh/config

Host github.com
  IdentityFile ~/.ssh/github_rsa_key

Assuming that you've named your private key ~/.ssh/github_rsa_key .假设您已将私钥命名为~/.ssh/github_rsa_key

Now try connecting to github:现在尝试连接到 github:

$ ssh git@github.com

You should see:你应该看到:

Hi <your github username>! You've successfully authenticated, but GitHub does not provide shell access.

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

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