Summary
For some reason, git commands don’t work the same when I am logged in as root. For example, when I’m logged in as a normal user, I can clone a repository, but I can’t clone that same repo into the same directory as root.
Example
Normal User:
> git clone git@192.168.1.103:testing
Cloning into 'testing'...
Enter passphrase for key '/home/Matthew/.ssh/id_rsa':
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
(then I su to root and remove the repo…)
Root:
# git clone git@192.168.1.103:testing
Cloning into 'testing'...
Password:
Password:
Password:
Permission denied (publickey,keyboard-interactive).
fatal: The remote end hung up unexpectedly
My Troubleshooting Attempts
At first I assumed this was some sort of problem related to ssh, but ssh-ing from every way possible seems to work normally. (I did not change the setting to enable you to login directly as root via ssh.)
Setup Details
- I’ve generated ssh keys for both the root and the other user.
- the machine I’m trying to clone the repos to is running FreeBSD 9 (I just installed it- trying to learn about *nix, hosting, sys admin, etc.)
- git server is gitolite on a mac (I’ve been using it for awhile without problems)
Conclusion
I have a feeling that this will be obvious to someone with more *nix/git chops, but I’ve failed so far to figure it out/find the answer on the interwebs. Thanks for any help!
The Problem
Note that your mortal user isn’t being prompted for a password, but your super user is. That’s a big clue that root’s private key isn’t loaded into an accessible ssh-agent.
The Solution
After you su to root, you need to start your ssh-agent and load your keys. For example:
If your keys are visible in your agent using
ssh-add -lthen you should be able to successfully clone at this point.Caveats
Since you’re using gitolite on the server, you can’t use password authentication–you must use public key authentication. To make this work, you will also need to make sure that you’ve added root’s public key to your gitolite configuration, and authorized the root user for whatever repositories you want that account to access.