在 Git 上执行 shell 命令时如何指定要使用的私有 SSH 密钥?
可能是一种相当不寻常的情况,但我想指定一个私有 SSH 密钥,以便在git
从本地计算机执行 shell ( ) 命令时使用。
基本上是这样的:
git clone git@github.com:TheUser/TheProject.git -key "/home/christoffer/ssh_keys/theuser"
甚至更好(在 Ruby 中):
with_key("/home/christoffer/ssh_keys/theuser") do
sh("git clone git@github.com:TheUser/TheProject.git")
end
Net::SSH
我已经看到使用指定私钥连接到远程服务器的示例,但这是一个本地命令。可能吗?
-
这些解决方案都不适合我。
相反,我详细说明了@Martin v. Löwis 提到
config
为 SSH 设置文件。SSH 将查找用户的
~/.ssh/config
文件。我的设置为:Host gitserv Hostname remote.server.com IdentityFile ~/.ssh/id_rsa.github IdentitiesOnly yes # see NOTES below
我添加了一个远程 git 存储库:
git remote add origin git@gitserv:myrepo.git
然后 git 命令对我来说正常工作。
git push -v origin master
笔记
- 这
IdentitiesOnly yes
是防止 SSH 默认行为发送与每个协议的默认文件名匹配的身份文件所必需的。如果您有一个名为的文件,在没有此选项的情况下~/.ssh/id_rsa
将在您之前尝试。~/.ssh/id_rsa.github
- 这
-
为给定域的 git push 指定 SSH 密钥
2022-03-22 关注 0 浏览37 1答案
-
如何使用SSH密钥配置Hudson和git插件
2021-02-01 关注 0 浏览107 1答案
-
在Python Paramiko中的SSH服务器上的辅助Shell /命令中执行(子)命令
2021-01-29 关注 0 浏览85 1答案
-
使用Python在SSH上执行命令
2021-02-02 关注 0 浏览128 1答案
-
在Jenkins for Git中管理SSH密钥
2021-01-31 关注 0 浏览129 1答案
-
为Elastic Beanstalk上的github私有存储库访问设置SSH密钥
2021-01-31 关注 0 浏览77 1答案
-
如何在Jenkins中通过ssh-agent在Windows上直接使用git
2021-01-31 关注 0 浏览117 1答案
-
SQLalchemy指定要使用的索引
2021-04-20 关注 0 浏览54 1答案
-
Windows从站上的Jenkins Git SSH密钥
2021-01-31 关注 0 浏览88 1答案
-
Git 不断询问我的 ssh 密钥密码
2022-03-22 关注 0 浏览37 1答案