使用指定的 SSH key 操作 git
Posted adream307
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用指定的 SSH key 操作 git相关的知识,希望对你有一定的参考价值。
Starting from Git 2.3.0 we also have the simple command (no config file needed):
GIT_SSH_COMMAND='ssh -i private_key_file -o IdentitiesOnly=yes' git clone user@host:repo.git
With git 2.10+ (Q3 2016: released Sept. 2d, 2016), you have the possibility to set a config for GIT_SSH_COMMAND
A new configuration variable core.sshCommand
has been added to specify what value for GIT_SSH_COMMAND
to use per repository.
cd /path/to/my/repo/already/cloned
git config core.sshCommand 'ssh -i private_key_file -o IdentitiesOnly=yes'
# later on
git pull
参考资料
- https://stackoverflow.com/questions/4565700/how-to-specify-the-private-ssh-key-to-use-when-executing-shell-command-on-git
- https://stackoverflow.com/questions/4565700/how-to-specify-the-private-ssh-key-to-use-when-executing-shell-command-on-git/38474137#38474137
以上是关于使用指定的 SSH key 操作 git的主要内容,如果未能解决你的问题,请参考以下文章