如何将 ssh 密钥路径添加到 git 命令终端
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18726252/
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
How to add ssh key path to a git command terminal
提问by Krotz
The thing is that I do not have root permissions on the remote server and can't use the default ssh key location due to the same problem, even if they are for the user I am currently using the destination is OFF LIMITS.
问题是我在远程服务器上没有 root 权限,并且由于同样的问题而无法使用默认的 ssh 密钥位置,即使它们是针对我当前使用的用户,目标是 OFF LIMITS。
I have found out I can create an ssh in a custom folder now I can't seem to find a way to pass that to git. To make it clear I can't edit the config file nor can I use any root commands.
我发现我现在可以在自定义文件夹中创建一个 ssh,我似乎找不到将它传递给 git 的方法。明确地说,我不能编辑配置文件,也不能使用任何根命令。
There might be something like git -i ssh/path
but I can't seem to find any documentation on this issue, for all I know this might not be even possible.
可能有类似的东西,git -i ssh/path
但我似乎找不到关于这个问题的任何文档,据我所知,这甚至可能是不可能的。
If anyone has found a solution to this any guidance is greatly appreciated!
如果有人找到了解决方案,我们将不胜感激!
EDIT : SOLUTION
编辑:解决方案
采纳答案by Ted Percival
Use the environment variable GIT_SSH
to alter the ssh command that Git uses and specify the path to the private key file:
使用环境变量GIT_SSH
更改 Git 使用的 ssh 命令并指定私钥文件的路径:
GIT_SSH='ssh -i /home/user/id_rsa'
GIT_SSH='ssh -i /home/user/id_rsa'
回答by supaflysnooka
From the Atlassian how-to doc, located here:
来自 Atlassian how-to doc,位于此处:
https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html
Open a terminal window and enter the ps -e | grep [s]sh-agent command to see if the agent is running.
$ ps -e | grep [s]sh-agent 9060 ?? 0:00.28 /usr/bin/ssh-agent -l
If the agent isn't running, start it manually with the following command:
$ ssh-agent /bin/bash
Load your new identity into the ssh-agent management program using the ssh-add command.
$ ssh-add ~/.ssh/id_rsa
Enter passphrase for /Users/emmap1/.ssh/id_rsa:
$ Identity added: /Users/emmap1/.ssh/id_rsa (/Users/emmpa1/.ssh/id_rsa)
Use the ssh-add command to list the keys that the agent is managing.
$ ssh-add -l 2048 7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 /Users/manthony/.ssh/id_rsa (RSA)
打开终端窗口并输入 ps -e | grep [s]sh-agent 命令查看代理是否正在运行。
$ ps -e | grep [s]sh-agent 9060 ?? 0:00.28 /usr/bin/ssh-agent -l
如果代理未运行,请使用以下命令手动启动它:
$ ssh-agent /bin/bash
使用 ssh-add 命令将您的新身份加载到 ssh-agent 管理程序中。
$ ssh-add ~/.ssh/id_rsa
输入 /Users/emmap1/.ssh/id_rsa 的密码:
$ Identity added: /Users/emmap1/.ssh/id_rsa (/Users/emmpa1/.ssh/id_rsa)
使用 ssh-add 命令列出代理正在管理的密钥。
$ ssh-add -l 2048 7a:9c:b2:9c:8e:4e:f4:af:de:70:77:b9:52:fd:44:97 /Users/manthony/.ssh/id_rsa (RSA)
Hope this helps...
希望这可以帮助...