9

I set up etckeeper and added the file /etc/etckeeper/commit.d/60github-push in order to push the commit to 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

However, pushing to github fails as etckeeper tries to push as root. Should the use of sudo not preserve my user account settings for git, including my ~/.ssh keys?

[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.
orschiro
  • 193
  • 1
  • 5
  • 10
    Please make your `etckeeper` repository private. Your `passwd` and `shadow` files are currently world readable. There are usually lots of other sensitive files in `/etc/` such as SSL keys. You should now change **all** the current secrets in there, including your password and the root password, everywhere you have used them. – Ladadadada Apr 01 '13 at 08:41

4 Answers4

8

To preserve the current ssh keys for when you're in root, use sudo -E. That way there's no need to add anything to the root ssh config

Andre
  • 96
  • 1
  • 2
3

If anyone has an issue with git still trying to use id_rsa instead of the key specified in /root/.ssh/config, here's my fix for it.

The following are my test configuration files before fixing them:

/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/*

There are two problems with this:

  1. SSH seems to require you to use the "Host" variable in place of [user]@[address|domain]
  2. The configuration file seems to need the private key.

To fix the first problem I edited line 7 in [repo]/.git/config from:

url = git@bitbucket.org:trae32566/test.git

to:

url = bitbucket:trae32566/test.git

To fix the second problem I edited line 4 in /root/.ssh/config from:

IdentityFile /root/.ssh/bitbucket.pub

to:

IdentityFile /root/.ssh/bitbucket

source: http://www.cyberciti.biz/faq/create-ssh-config-file-on-linux-unix/

aksh1618
  • 103
  • 4
Trae32566
  • 31
  • 2
2

One thing you can do is specify a key to use for one repo and set it as a remote in your git repository.

Meaning you can put this in root's ~/.ssh/config:

Host gitupstream
        HostName example.org
        User git
        IdentityFile /home/<user>/.ssh/id_rsa.pub

Assuming you git remote add gitupstream git@example.org:/myrepo in this case then do git push origin gitupstream.

gparent
  • 3,561
  • 2
  • 23
  • 28
  • Thanks. Pushing to Github is working now. However, the author being displayed is wrong. It shows `Author: orschiro ` which is different to what `git config --global user.name` and `git config --global user.email` show. – orschiro Apr 01 '13 at 01:17
  • You'll need to run that command as root too. – gparent Apr 01 '13 at 01:21
  • 1
    This did not fix it. I had to uncomment lines 43 to 53 in `etckeeper/commit.d/50vcs-commit` which export `GIT_AUTHOR_NAME` and so one and thus overwrite my global setting. – orschiro Apr 01 '13 at 01:42
  • Yeah, it won't fix it if you don't do it properly. It's a set up I run and it works fine. – gparent Aug 29 '14 at 19:36
0

sudo will not preserve your ~/.ssh keys. This is due to the fact that you are now root running that command. So it's going to look for root's ssh keys. So you'd have to create a key for root and add that to your github user.

Mike
  • 21,910
  • 7
  • 55
  • 79