如何将ssh密钥路径添加到git命令终端

8
问题在于我在远程服务器上没有root权限,由于同样的问题,无法使用默认的ssh密钥位置,即使它们是为我当前使用的用户而设计的,目标也是禁止访问的。
我已经发现我可以在自定义文件夹中创建一个ssh,但我似乎找不到一种将其传递给git的方法。为了明确起见,我不能编辑配置文件,也不能使用任何root命令。
可能会有类似git -i ssh/path的东西,但我似乎找不到这个问题的任何文档,据我所知,这甚至可能是不可能的。
如果有人找到了解决方案,任何指导都将不胜感激!
编辑:解决方案 使用GIT_SSH错误进行带有自定义SSH的Git克隆

1
解决方案?http://www.boxtricks.com/how-to-specify-an-ssh-key-with-git/ - samsquanch
2个回答

8

以下是Atlassian的操作指南,位于此处:

https://confluence.atlassian.com/bitbucket/set-up-ssh-for-git-728138079.html


该文档介绍了如何为Git设置SSH。
  1. 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
    
  2. If the agent isn't running, start it manually with the following command:

    $ ssh-agent /bin/bash
    
  3. Load your new identity into the ssh-agent management program using the ssh-add command.

    $ ssh-add ~/.ssh/id_rsa
    
  4. Enter passphrase for /Users/emmap1/.ssh/id_rsa:

    $ Identity added: /Users/emmap1/.ssh/id_rsa (/Users/emmpa1/.ssh/id_rsa)
    
  5. 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)
    
希望这可以帮助到您...

4

使用环境变量GIT_SSH来更改Git使用的ssh命令,并指定私钥文件的路径:

GIT_SSH='ssh -i /home/user/id_rsa'


好的,所以我最终尝试了这个,但出现某些原因找不到文件(我已经检查过它们是否存在)“/usr/bin/ssh -o StrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -i /home/robert/press.lo/wp-content/.repos/.ssh/id_rsa”:没有那个文件或目录 fatal: unable to fork - Krotz
身份文件(私钥)存储在您的本地计算机上,而不是远程服务器上。 - T Percival
我在本地使用XAMPP,所以我不明白:D - Krotz
1
GIT_SSH默认不接受在设置中设置的选项,但我成功将其指向一个执行此操作的脚本文件:D谢谢! - Krotz

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接