Git
etckeeper 推送到 github
我設置了 etckeeper 並添加了文件
/etc/etckeeper/commit.d/60github-push
以將送出推送到 github。[orschiro@thinkpad etc]$ sudo cat /etc/etckeeper/commit.d/60github-push #!/bin/sh set -e if [ "$VCS" = git ] && [ -d .git ]; then cd /etc/ git push origin master fi
但是,由於 etckeeper 嘗試以 root 身份推送,因此推送到 github 失敗。是否應該使用 sudo 不保留我的 git 使用者帳戶設置,包括我的 ~/.ssh 密鑰?
[orschiro@thinkpad etc]$ sudo etckeeper commit "test" [master de5971c] test Author: orschiro <orschiro@thinkpad.(none)> 3 files changed, 2 insertions(+), 1 deletion(-) rename etckeeper/{ => commit.d}/60github-push (100%) create mode 100644 test no such identity: /root/.ssh/id_rsa: No such file or directory no such identity: /root/.ssh/id_dsa: No such file or directory no such identity: /root/.ssh/id_ecdsa: No such file or directory Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
要在您處於 root 身份時保留目前的 ssh 密鑰,請使用
sudo -E
. 這樣就無需在根 ssh 配置中添加任何內容
如果有人對 git 仍然嘗試使用 id_rsa 而不是 /root/.ssh/config 中指定的密鑰有疑問,這是我的解決方法。
以下是我在修復它們之前的測試配置文件:
/root/.ssh/config:
Host bitbucket HostName bitbucket.org User git IdentityFile /root/.ssh/bitbucket.pub
$$ repo $$/.git/config:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = git@bitbucket.org:trae32566/test.git fetch = +refs/heads/*:refs/remotes/origin/*
這有兩個問題:
- SSH 似乎要求您使用“主機”變數代替$$ user $$@$$ address|domain $$
- 配置文件似乎需要私鑰。
為了解決第一個問題,我編輯了第 7 行
$$ repo $$/.git/config 來自:
url = git@bitbucket.org:trae32566/test.git
到:
url = bitbucket:trae32566/test.git
為了解決第二個問題,我在 /root/.ssh/config 中編輯了第 4 行:
IdentityFile /root/.ssh/bitbucket.pub
到:
IdentityFile /root/.ssh/bitbucket
來源: http ://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/