![](/img/trans.png)
[英]How to apply Dockerfile `git config` values to a non-root user's ssh session?
[英]How to configure ssh agent service and keys for git deployments using non-root user?
進行部署(使用非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.
將信息存儲在~/.ssh/config
:
Host hostname
IdentityFile ~/.ssh/deploymapr
或將密鑰移動到標准位置( ~/.ssh/id_rsa
或相應的手冊頁)。
創建SSH配置文件機制來為各種身份創建別名。
您可以使用許多參數和不同方法來構造SSH配置文件。
本示例中使用的別名條目的格式為:
Host alias HostName bitbucket.org IdentityFile ~/.ssh/identity
要為兩個身份(workid和personalid)創建配置文件,請執行以下操作:
Open a terminal window.
Edit the ~/.ssh/config file.
如果沒有配置文件,請創建一個。
為每個標識組合添加一個別名,例如:
Host workid
HostName bitbucket.org
IdentityFile ~/.ssh/workid
Host personalid
HostName bitbucket.org
IdentityFile ~/.ssh/personalid
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.