.ssh/windows 配置文件 (git)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26266778/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.ssh/config file for windows (git)
提问by mathew11
I've been looking for a solution on how I can use multiple ssh keys and I figured out, that it will work with a config file in the .ssh directory, but it doesn't work on windows.
我一直在寻找关于如何使用多个 ssh 密钥的解决方案,我发现它可以与 .ssh 目录中的配置文件一起使用,但它不适用于 Windows。
My problem is that I'm using a private key to access a git server, so it looks like this: ssh://[email protected]/directory , it works fine when I'm using TortoiseGit, 'cause there is a possibility to choose the private key.
我的问题是我使用私钥访问 git 服务器,所以它看起来像这样: ssh://[email protected]/directory ,当我使用 TortoiseGit 时它工作正常,因为有一个选择私钥的可能性。
But I want to use the git rep in my IntelliJ IDEA and there is just the option to use the git native shell and it also works, if I put the key, called id_rsa ,into the .ssh folder. Now I want to use multiple ssh keys (so my key will get the name "id_rsa_test", so how do I configure the .ssh/config file under Windows, that it works with a usual git server?
但是我想在我的 IntelliJ IDEA 中使用 git rep 并且只有使用 git native shell 的选项,如果我将名为 id_rsa 的密钥放入 .ssh 文件夹,它也可以工作。现在我想使用多个 ssh 密钥(所以我的密钥将获得名称“id_rsa_test”,那么我如何在 Windows 下配置 .ssh/config 文件,它可以与普通的 git 服务器一起使用?
The most examples I found yet are just for the use with github.
我发现的大多数示例仅用于 github。
回答by LennyLip
If you use "Git for Windows"
如果您使用“Windows 版 Git”
>cd c:\Program Files\Git\etc\ssh\
add to ssh_config following:
添加到 ssh_config 以下:
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
IdentityFile ~/.ssh/id_rsa_test
ps. you need ssh version >= 7.2 (date of release 2016-02-28)
附:您需要 ssh 版本 >= 7.2(发布日期 2016-02-28)
回答by pauljohn32
These instructions work fine in Linux. In Windows, they are not working for me today.
这些说明在 Linux 中运行良好。在 Windows 中,它们今天对我不起作用。
I found an answer that helps for me, maybe this will help OP. I kissed a lot of frogs trying to solve this. You need to add your new non-standard-named key file with "ssh-add"! Here's instruction for the magic bullet: Generating a new SSH key and adding it to the ssh-agent. Once you know the magic search terms are "add key with ssh-add in windows" you find plenty of other links.
我找到了一个对我有帮助的答案,也许这会对 OP 有所帮助。我亲了很多青蛙试图解决这个问题。您需要使用“ssh-add”添加新的非标准命名的密钥文件!以下是灵丹妙药的说明:生成新的 SSH 密钥并将其添加到 ssh-agent。一旦您知道神奇的搜索词是“在 Windows 中使用 ssh-add 添加密钥”,您就会发现许多其他链接。
If I were using Windows often, I'd find some way to make this permanent. https://github.com/raeesbhatti/ssh-agent-helper.
如果我经常使用 Windows,我会找到某种方法使其永久化。https://github.com/raeesbhatti/ssh-agent-helper。
The ssh key agent looks for default "id_rsa" and other keys it knows about. The key you create with a non-standard name must be added to the ssh key agent.
ssh 密钥代理查找默认的“id_rsa”和它知道的其他密钥。您使用非标准名称创建的密钥必须添加到 ssh 密钥代理。
First, I start the key agent in the Git BASH shell:
首先,我在 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)
Then I change to the directory where I want to clone the repo
然后我切换到我想要克隆 repo 的目录
$ cd ~/Documents/GIT/
$ git clone [email protected]: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.
I fought with this for a long long time.
我与这个斗争了很长时间。
Here are other things I tried along the way
这是我一路上尝试过的其他事情
At first I was certain it is because of file and folder permissions. On Linux, I have seen .ssh settings rejected if the folder is not set at 700. Windows has 711. In Windows, I cannot find any way to make permissions 700.
起初我确定这是因为文件和文件夹权限。在 Linux 上,如果文件夹未设置为 700,我看到 .ssh 设置被拒绝。Windows 有 711。在 Windows 中,我找不到任何方法将权限设置为 700。
After fighting with that, I think it must not be the problem. Here's why. If the key is named "id_rsa" then git works! Git is able to connect to server. However, if I name the key file something else, and fix the config file in a consistent way, no matter what, then git fails to connect. That makes me think permissions are not the problem.
在与那个斗争之后,我认为这一定不是问题。这是为什么。如果键名为“id_rsa”,则 git 可以工作!Git 能够连接到服务器。但是,如果我将密钥文件命名为其他名称,并以一致的方式修复配置文件,无论如何,git 都无法连接。这让我认为权限不是问题。
A thing you can do to debug this problem is to watch verbose output from ssh commands using the configured key.
调试此问题可以做的一件事是使用配置的密钥查看 ssh 命令的详细输出。
In the git bash shell, run this
在 git bash shell 中,运行这个
$ ssh -T git@name-of-your-server
Note, the user name should be "git" here. If your key is set up and the config file is found, you see this, as I just tested in my Linux system:
注意,这里的用户名应该是“git”。如果您设置了密钥并找到了配置文件,您会看到这一点,正如我刚刚在我的 Linux 系统中测试的那样:
$ ssh -T [email protected]
Welcome to GitLab, Paul E. Johnson!
On the other hand, in Windows I have same trouble you do before applying "ssh-add". It wants git's password, which is always a fail.
另一方面,在 Windows 中,我在应用“ssh-add”之前遇到了同样的麻烦。它想要git的密码,这总是失败。
$ ssh -T [email protected]
[email protected]'s password:
Again, If i manually copy my key to "id_rsa" and "id_rsa.pub", then this works fine. After running ssh-add, observe the victory in Windows Git BASH:
同样,如果我手动将密钥复制到“id_rsa”和“id_rsa.pub”,那么这可以正常工作。运行 ssh-add 后,观察 Windows Git BASH 中的胜利:
$ ssh -T [email protected]
Welcome to GitLab, Paul E. Johnson!
You would hear the sound of me dancing with joy if you were here.
如果你在这里,你会听到我高兴地跳舞的声音。
To figure out what was going wrong, you can I run 'ssh' with "-Tvv"
要弄清楚出了什么问题,您可以使用“-Tvv”运行“ssh”
In Linux, I see this when it succeeds:
在 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).
In Windows, when this fails, I see it looking for default names:
在 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
[email protected]'s password:
That was the hint I needed, it says it finds my ~/.ssh/config file but never tries the key I want it to try.
这就是我需要的提示,它说它找到了我的 ~/.ssh/config 文件,但从未尝试过我想让它尝试的密钥。
I only use Windows once in a long while and it is frustrating. Maybe the people who use Windows all the time fix this and forget it.
我很长一段时间只使用一次 Windows,这很令人沮丧。也许一直使用 Windows 的人解决了这个问题并忘记了它。
回答by phts
There is an option IdentityFile
which you can use in your ~/.ssh/config
file and specify key file for each host.
IdentityFile
您可以在~/.ssh/config
文件中使用一个选项,并为每个主机指定密钥文件。
Host host_with_key1.net
IdentityFile ~/.ssh/id_rsa
Host host_with_key2.net
IdentityFile ~/.ssh/id_rsa_test
More info: http://linux.die.net/man/5/ssh_config
更多信息:http: //linux.die.net/man/5/ssh_config
Also look at http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
另请参阅 http://nerderati.com/2011/03/17/simplify-your-life-with-an-ssh-config-file/
回答by valdeci
For me worked only adding the config
file that was on the dir ~/.ssh/config
on my Linux system on the c:\Program Files\Git\etc\ssh\
directory on Windows.
对我来说有效只添加config
这是对目录的文件~/.ssh/config
在我的Linux系统上c:\Program Files\Git\etc\ssh\
的Windows目录。
After that, I was be able to use all the alias and settings that I normally used on my Linux connecting or pushing via SSH on the Git Bash.
之后,我能够使用我通常在 Linux 上使用的所有别名和设置,通过Git Bash上的 SSH 连接或推送。