【发布时间】:2016-04-24 05:42:36
【问题描述】:
我在进行部署时遇到了问题(使用非 root 用户):
$> git pull
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
经过一番挖掘,我找到了适合我的解决方法:
$> eval $(ssh-agent)
Agent pid 61080
$> ssh-add ~/.ssh/deploymapr
Identity added: /home/mapr/.ssh/deploymapr (/home/mapr/.ssh/deploymapr)
$> git pull
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 10 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (10/10), done.
⋮
现在我经常进行部署 - 每次登录部署服务器时都需要重复上述步骤,这有点麻烦。
我确信有更好、更优雅的方式来为普通用户配置它(我不是在谈论将这两行添加到~/.bashrc...)。有什么想法吗?
更新:根据下面的答案,我已经配置了我的~/.ssh/config 文件:
stat -c "%A %a %n" ~/.gitconfig ~/.ssh/deploymapr ~/.ssh/config
-rw-rw-r-- 664 /home/mapr/.gitconfig
-rw------- 600 /home/mapr/.ssh/deploymapr
-rw-r--r-- 644 /home/mapr/.ssh/config
但我仍然收到错误(当不运行解决方法时=上面的两个命令,手动):
$ git pull
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
【问题讨论】:
标签: git ssh ssh-keys sshd ssh-agent