问题
The following set of commands worked correctly
$ mkdir carboncake
$ cd carboncake
$ git init
$ git remote add origin gitosis@myserver.net:repositories/carboncake.git
$ git pull
But when i tried pull as a different user,
$ mkdir carboncake
$ cd carboncake
$ git init
$ git remote add origin mithun@myserver.net:repositories/carboncake.git
$ git pull
I got the following error
fatal: 'repositories/carboncake.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
my gitosis.conf
contains
[gitosis]
[group team]
writable = sweepshots
members = git_id_rsa
[group gitosis-admin]
writable = gitosis-admin
members = git_id_rsa
[repo carboncake]
description = A brand new app by Mithun.
owner = Mithun P
[group carboncake]
writable = carboncake
members = mithun @core
and the keydir
contains
git_id_rsa.pub KEY-----.pub mithun.pub mithun-rsa-key-20110427.pub
and the user's .ssh
dir contains
mithun@testserver:~$ ls .ssh/
id_rsa id_rsa.pub mithun_rsa mithun_rsa.pub
-- UPDATE
I tried $ git remote add origin mithun@myserver.net:carboncake.git
too, but the same error.
Actually carboncake.git is located at /srv/gitosis/repositories/carboncake.git
回答1:
mithun@myserver.net
?
By using mithun@myserver.net
, you are bypassing gitosis completely, since the correct url would involve the 'git
' user under which gitolite has been installed.
Every gitosis commands would involve the same 'git' user: gitosis@myserver.net
(assuming a 'gitosis' account here).
Plus, you shouldn't have to specify the full path of the repo:
git remote add origin gitosis@myserver.net:carboncake.git
回答2:
To add a little plain-english clarity to @VonC's (entirely correct) answer...
gitosis (which is no longer in active development and you should be using gitolite, but this answer applies to both of them) stores each user's public keys in (in your case) ~gitosis/.ssh/authorized_keys
. When a user ssh'es to the account gitosis
, ssh does a cryptographic handshake, finds a line in that authorized_keys file that matches the provided key, and does whatever that line says to do. If you look at that authorized_keys file, each line supplies a command to call when that user logs in, which is a call to the gitosis process, carrying the name of the user in question.
So each user is REALLY ssh'ing to the SAME gitosis
"machine" account, but the key they SSH there with fires up gitosis AS the user they are. That's how gitosis knows which user it's talking to even though they've logged into the same "machine" account named gitosis
.
So every local repo you want to track to gitosis needs to be given a remote of the format gitosis@your.server:<reponame>.git
.
来源:https://stackoverflow.com/questions/5803404/git-authentication-pull-as-a-new-user