首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将Git配置为从特定位置使用.pem密钥

将Git配置为从特定位置使用.pem密钥
EN

Stack Overflow用户
提问于 2015-06-22 05:43:55
回答 4查看 15.6K关注 0票数 12

每当我尝试做一个'git拉起源大师‘,我得到(这不是吉特布):

拒绝许可(公开密钥)

我能够将SSH放入我的AWS服务器中,该服务器有一个裸露的存储库,当我得到上述权限错误时,我正试图从中提取这个存储库。

我确实将公钥复制到该服务器,因为我可以通过ssh成功登录,但只能执行以下操作:

ssh -i /location/of/pemkey/mykey.pem ec2-user@ec2-12-34-56-78.us-east-compute.amazonaws.com

我需要配置Git来使用我的“.pem”密钥。如何完成设置Git来使用我的“.pem”密钥?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2015-06-22 06:16:47

来自git(1)手册页:

代码语言:javascript
复制
   GIT_SSH
       If this environment variable is set then git fetch and git push
       will use this command instead of ssh when they need to connect to a
       remote system. The $GIT_SSH command will be given exactly two or
       four arguments: the username@host (or just host) from the URL and
       the shell command to execute on that remote system, optionally
       preceded by -p (literally) and the port from the URL when it
       specifies something other than the default SSH port.

       To pass options to the program that you want to list in GIT_SSH you
       will need to wrap the program and options into a shell script, then
       set GIT_SSH to refer to the shell script.

       Usually it is easier to configure any desired options through your
       personal .ssh/config file. Please consult your ssh documentation
       for further details.

在我个人的经验中,在.ssh/config中添加主机设置的一次性成本已经产生了很大的不同,即使对于只有用户名不同的主机来说也是如此。

票数 5
EN

Stack Overflow用户

发布于 2015-06-22 06:40:51

我是从here那里得到的,但这不是主要的答案。这里列出的说明对我更有用。

调整您的~/..ssh/config并添加:

代码语言:javascript
复制
Host example
Hostname example.com
User myuser
IdentityFile ~/.ssh/other_id_rsa

现在使用ssh主机别名作为存储库:

代码语言:javascript
复制
$ git remote add origin example:repository.git

$ git pull origin master

它应该使用other_id_rsa密钥!

票数 8
EN

Stack Overflow用户

发布于 2018-10-27 21:38:48

代码语言:javascript
复制
1. touch ~/.ssh/config
2. chmod 644 ~/.ssh/config
3. vim ~/.ssh/config
    #write next codeline
    host ec2-ip.eu-west-1.compute.amazonaws.com
    IdentityFile ~/Documents/ec2-user.pem

git clone git@ec2-ip.eu-west-1.compute.amazonaws.com:/home/git/my-repo.git
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30972776

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档