我没有〜/.ssh/config文件,但是有多个GitHub帐户有效,怎么办? [英] I don't have ~/.ssh/config file but multiple GitHub accounts works, how?

查看:241
本文介绍了我没有〜/.ssh/config文件,但是有多个GitHub帐户有效,怎么办?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试配置另一个GitHub帐户以能够在我的机器上工作.我开始四处张望,找到了:

I'm trying to configure another GitHub account to be able work from my machine. I started to looking around and I found:

通过创建/修改〜/.ssh/config来设置多个ssh配置文件.注意主机"值略有不同:

Set up multiple ssh profiles by creating/modifying ~/.ssh/config. Note the slightly differing 'Host' values:

因此,由于我(已经)有多个帐户在工作(我不记得我是怎么做的以及何时做的),我只想在~/.ssh/config中添加另一个条目.但是看来我没有这样的文件.也许它位于其他地方?还是我的机器以其他方式配置?从哪里开始搜索?

So as I (already) have multiple accounts working (I don't remember how and when I did that) I wanted to just add another entry in ~/.ssh/config. But it appears that I don't have such file. Maybe it is located somewhere else? Or maybe my machine is configured in some other way? Where to start searching?

推荐答案

这是 ssh 而不是git的行为.

This is behavior of ssh rather than git.

在您的~/.ssh文件夹中,您具有私钥.私钥的文件名默认为id_rsa.每当您的ssh客户端必须登录到ssh服务器时,它都会从该文件中读取密钥.

In your ~/.ssh folder you have your private key. The name of the file for your private key is id_rsa by default. When ever your ssh client has to login to a ssh server it reads the key from that file.

但是在某些情况下,您可能需要使用其他私钥进行身份验证.在这种情况下,您将创建文件~/.ssh/config,并添加带有别名(在命令行中输入的主机名),真实主机名以及本地系统上备用密钥文件的路径的部分:

But in some cases you may want to use a different private key for authentication. In that case you create the file ~/.ssh/config and you add a section with an alias (the host name you write at the command line) the real host name and the path to he alternative key file on your local system:

# ~/.ssh/config
Host alternative-github
    HostName github.com
    User MyOtherGithubUser
    IdentityFile /media/me/MyUsbThumbDrive/.ssh/MyOtherGithubUsers-id_rsa

在克隆存储库时,按以下配置 ssh 在UBS拇指驱动器上查找私钥:

Whit this configuration ssh looks on my UBS thumb drive for the private key when I clone the repo like this:

git clone git@alternative-github:/MyOtherGithubUser/someRepositoty.git

结论

只要您在git项目中使用相同的公钥/私钥对,并且私钥在~/.ssh/id_rsa中可用,就不需要文件~/.ssh/config.

conclusion

As long as you use the same public/private key pair with your git projects and the private key is available as ~/.ssh/id_rsa you don't need the file ~/.ssh/config.

这篇关于我没有〜/.ssh/config文件,但是有多个GitHub帐户有效,怎么办?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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