在Windows上的Git中的多个ssh密钥之间切换 [英] Switching between multiple ssh keys in Git on Windows
问题描述
我需要在客户端拥有多个密钥才能访问Repository托管中的两个不同帐户。请参阅 https://redefy.repositoryhosting.com/support - >如何使用多个密钥对管理多个帐户在我的客户端?
我不明白如何在Windows上的Git中的不同ssh密钥之间切换,任何人都可以帮助我?
就像文章中写的那样,你可以让ssh客户端的配置文件,列出您的所有帐户。您可以在〜/ .ssh / config
主机帐户 - 一个
HostName server.example.com
用户用户一
IdentityFile〜/ .ssh / key-one
Host account-two
HostName server.example.com
User user-two
IdentityFile〜/ .ssh / key-two
它定义了两种名为 account-one
和<$ c的主机别名 $ C>帐户二。如果你使用它们,当连接时,ssh客户端将使用相应的 HostName
, User
和 IdentityFile
作为服务器地址,用户名和ssh密钥文件。有了这个,你可以使用它们访问你的账户和密钥,甚至在同一台服务器上。
在git中,你可以使用它们定义两个遥控器。 b
$ git remote添加一个account-one:repository.git
$ git remote添加两个account-two:repository.git
然后您可以推送到这些遥控器
$ git push one master
$ git push two master
I need to have multiple keys in my client to access two different accounts on Repository hosting. See https://redefy.repositoryhosting.com/support -> How do I manage multiple accounts with multiple keypairs on my client?
I do not understand how to change between different ssh keys in Git on Windows, can anybody help me?
I assume you use git bash and openssh.
Like what it's written in the article, you can make a configuration file for ssh client that lists all of your accounts. You can write the following configuration in your own ssh client configuration file in ~/.ssh/config
Host account-one
HostName server.example.com
User user-one
IdentityFile ~/.ssh/key-one
Host account-two
HostName server.example.com
User user-two
IdentityFile ~/.ssh/key-two
What it says is you define two, kind of, "host aliases" named account-one
and account-two
. If you use them, when making connection, the ssh client will use the corresponding HostName
, User
, and IdentityFile
for the server address, username, and ssh key file. With this you can use them to access your accounts and keys at even the same server.
In git, you can define two remotes using them
$ git remote add one account-one:repository.git
$ git remote add two account-two:repository.git
then you can push to those remotes
$ git push one master
$ git push two master
这篇关于在Windows上的Git中的多个ssh密钥之间切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!