mat*_*w11 27 git ssh intellij-idea
我一直在寻找一个关于如何使用多个ssh密钥的解决方案,我发现它可以在.ssh目录中使用配置文件,但它不适用于Windows.
我的问题是,我使用的是私有密钥来访问git的服务器,所以它看起来是这样的:SSH://git@example.com/directory,它工作正常,当我使用TortoiseGit,"原因是有选择私钥的可能性.
但是我想在我的IntelliJ IDEA中使用git rep,只有使用git native shell的选项,如果我将名为id_rsa的密钥放入.ssh文件夹,它也可以工作.现在我想使用多个ssh密钥(因此我的密钥将获得名称"id_rsa_test",因此如何在Windows下配置.ssh/config文件,它是否适用于通常的git服务器?
我发现的大多数例子都只是用于github.
Len*_*Lip 28
如果您使用"Git for Windows"
>cd c:\Program Files\Git\etc\ssh\
Run Code Online (Sandbox Code Playgroud)
添加到ssh_config以下:
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/id_rsa_test
Run Code Online (Sandbox Code Playgroud)
PS.你需要ssh版本> = 7.2(发布日期2016-02-28)
Sve*_*ile 14
您可以在 Windows 10 上使用多个 ssh 密钥并指定允许的访问类型。
假设您已经创建了 ssh 安全密钥并且它们存储在 C:\Users\[User]\.ssh
打开文件夹 C:\Users\[User]\.ssh
创建文件config (无文件扩展名)
在记事本等文本编辑器中打开该文件,并为第一个远程主机和用户添加这些配置详细信息。保留 CMD 和 BASH 路径或只选择一种格式。然后在其下方复制并粘贴其他主机/用户组合并根据需要进行修改。保存文件。
Host [git.domain.com]
User [user]
Port [number]
IdentitiesOnly=yes
PreferredAuthentications publickey
PasswordAuthentication no
# CMD
IdentityFile C:\Users\[User]\.ssh\[name_of_PRIVATE_key_file]
# BASH
IdentityFile /c/Users/[User]/.ssh/[name_of_PRIVATE_key_file]
Run Code Online (Sandbox Code Playgroud)
测试
$ ssh -T git@[git.domain.com]
Welcome to GitLab, @[User]!
Run Code Online (Sandbox Code Playgroud)
C:\Users\[User]>ssh -T git@[git.domain.com]
Welcome to GitLab, @[User]!
Run Code Online (Sandbox Code Playgroud)
ssh -Tv git@[git.domain.com](或-Tvv或-Tvvv更高的详细级别)。pht*_*hts 10
IdentityFile您可以在~/.ssh/config文件中使用一个选项,并为每个主机指定密钥文件。
Host host_with_key1.net
IdentityFile ~/.ssh/id_rsa
Host host_with_key2.net
IdentityFile ~/.ssh/id_rsa_test
Run Code Online (Sandbox Code Playgroud)
更多信息:http : //linux.die.net/man/5/ssh_config
另请参阅 http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
这些说明在Linux中工作正常。在Windows中,他们今天不为我工作。
我找到了一个对我有用的答案,也许这会对OP有所帮助。我亲吻了很多试图解决这个问题的青蛙。您需要使用“ ssh-add”添加新的非标准命名密钥文件!以下是魔术项目符号的说明:生成新的SSH密钥并将其添加到ssh-agent。一旦知道魔术搜索术语是“在Windows中使用ssh-add添加密钥”,您就会发现许多其他链接。
如果我经常使用Windows,我会找到某种方法使它永久化。https://github.com/raeesbhatti/ssh-agent-helper。
ssh密钥代理查找默认的“ id_rsa”和它知道的其他密钥。您使用非标准名称创建的密钥必须添加到ssh密钥代理中。
首先,我在Git BASH shell中启动密钥代理:
$ eval $(ssh-agent -s)
Agent pid 6276
$ ssh-add ~/.ssh/Paul_Johnson-windowsvm-20180318
Enter passphrase for /c/Users/pauljohn32/.ssh/Paul_Johnson-windowsvm-20180318:
Identity added: /c/Users/pauljohn32/.ssh/Paul_Johnson-windowsvm-20180318 (/c/Users/pauljohn32/.ssh/Paul_Johnson-windowsvm-20180318)
Run Code Online (Sandbox Code Playgroud)
然后我转到要克隆存储库的目录
$ cd ~/Documents/GIT/
$ git clone git@git.ku.edu:test/spr2018.git
Cloning into 'spr2018'...
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Run Code Online (Sandbox Code Playgroud)
我为此战斗了很长时间。
这是我尝试过的其他方法
起初,我确定这是由于文件和文件夹权限所致。在Linux上,如果文件夹未设置为700,我会看到.ssh设置被拒绝。Windows的设置为711。在Windows中,我找不到任何将权限设置为700的方法。
经过这样的斗争,我认为这一定不是问题。这就是为什么。如果密钥名为“ id_rsa”,则git可以正常工作!Git能够连接到服务器。但是,如果我将密钥文件命名为其他名称,并且以一致的方式修复配置文件,无论如何,git将无法连接。这使我认为权限不是问题。
要调试此问题,您可以做的事情是使用已配置的密钥查看ssh命令的详细输出。
在git bash shell中,运行此命令
$ ssh -T git@name-of-your-server
Run Code Online (Sandbox Code Playgroud)
注意,此处的用户名应为“ git”。如果设置了密钥并找到了配置文件,那么您将看到这,就像我刚刚在Linux系统中测试的那样:
$ ssh -T git@git.ku.edu
Welcome to GitLab, Paul E. Johnson!
Run Code Online (Sandbox Code Playgroud)
另一方面,在Windows中,在应用“ ssh-add”之前您遇到了同样的麻烦。它需要git的密码,这总是失败的。
$ ssh -T git@gitlab.crmda.ku.edu
git@gitlab.crmda.ku.edu's password:
Run Code Online (Sandbox Code Playgroud)
同样,如果我手动将密钥复制到“ id_rsa”和“ id_rsa.pub”,则可以正常工作。运行ssh-add之后,观察Windows Git BASH的胜利:
$ ssh -T git@gitlab.crmda.ku.edu
Welcome to GitLab, Paul E. Johnson!
Run Code Online (Sandbox Code Playgroud)
如果您在这里,您会听到我快乐地跳舞的声音。
要找出问题出在哪里,您可以使用“ -Tvv”运行“ ssh”
在Linux中,成功时会看到以下信息:
debug1: Offering RSA public key: pauljohn@pols124
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp SHA256:bCoIWSXE5fkOID4Kj9Axt2UOVsRZz9JW91RQDUoasVo
debug1: Authentication succeeded (publickey).
Run Code Online (Sandbox Code Playgroud)
在Windows中,如果失败,我会看到它正在寻找默认名称:
debug1: Found key in /c/Users/pauljohn32/.ssh/known_hosts:1
debug2: set_newkeys: mode 1
debug1: rekey after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey after 4294967296 blocks
debug2: key: /c/Users/pauljohn32/.ssh/id_rsa (0x0)
debug2: key: /c/Users/pauljohn32/.ssh/id_dsa (0x0)
debug2: key: /c/Users/pauljohn32/.ssh/id_ecdsa (0x0)
debug2: key: /c/Users/pauljohn32/.ssh/id_ed25519 (0x0)
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: publickey
debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_rsa
debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_dsa
debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/pauljohn32/.ssh/id_ed25519
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
git@gitlab.crmda.ku.edu's password:
Run Code Online (Sandbox Code Playgroud)
那就是我需要的提示,它说它找到我的〜/ .ssh / config文件,但是从不尝试我想要它尝试的密钥。
我只使用Windows很长时间,这令人沮丧。也许一直使用Windows的人会解决此问题并忘记它。
| 归档时间: |
|
| 查看次数: |
48457 次 |
| 最近记录: |