我设置了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.
为了保留当前的ssh密钥,使用sudo -E 。 这样就没有必要添加任何东西到根sshconfiguration
你可以做的一件事是指定一个密钥用于一个回购,并将其设置为您的git存储库中的远程。
意思是你可以把它放在根目录的~/.ssh/config :
Host gitupstream HostName example.org User git IdentityFile /home/<user>/.ssh/id_rsa.pub
假设你git remote add gitupstream [email protected]:/myrepo在这种情况下,然后做git push origin gitupstream 。
如果任何人有与git仍然尝试使用id_rsa而不是/root/.ssh/config中指定的密钥的问题,这是我的修复它。
在修复它们之前,以下是我的testingconfiguration文件:
/root/.ssh/config:
Host bitbucket HostName bitbucket.org User git IdentityFile /root/.ssh/bitbucket.pub
[回购] / GIT中/configuration:
[core] repositoryformatversion = 0 filemode = true bare = false logallrefupdates = true [remote "origin"] url = [email protected]:trae32566/test.git fetch = +refs/heads/*:refs/remotes/origin/*
这有两个问题:
要解决第一个问题,我从/root/.ssh/config中编辑第7行:
url = [email protected]:trae32566/test.git
至:
url = bitbucket:trae32566/test.git
为了解决第二个问题,我在[repo] /。git / config中编辑了第4行:
IdentityFile /root/.ssh/bitbucket.pub
至:
IdentityFile /root/.ssh/bitbucket
来源: http : //www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/
sudo不会保留你的〜/ .ssh键。 这是因为你现在正在运行root命令。 所以它会查找root的ssh密钥。 所以你必须为root创build一个密钥,并将其添加到你的github用户。