etckeeper 推送到 github

ors*_*iro 8 git etckeeper

我设置了 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
Run Code Online (Sandbox Code Playgroud)

但是,推送到 github 失败,因为 etckeeper 尝试以 root 身份推送。是否应该使用 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.
Run Code Online (Sandbox Code Playgroud)

小智 8

要在 root 用户身份时保留当前的 ​​ssh 密钥,请使用sudo -E. 这样就不需要在根 ssh 配置中添加任何内容