{"thread":{"id":"52886","subject":"git-shell default working directory","startedAt":"2020-02-26T00:48:36Z","lastAt":"2020-02-28T20:40:43Z","messageCount":7,"participants":["Greg Anders","Andrei Rybak","Jeff King","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"392498","messageId":"20200226004830.oxd5562v7qqspnkk@Kepler","threadId":"52886","inReplyTo":null,"subject":"git-shell default working directory","fromName":"Greg Anders","fromEmail":"greg@gpanders.com","sentAt":"2020-02-26T00:48:30Z","receivedAt":"2020-02-26T00:48:36Z","isPatch":false,"sender":{"key":"greg@gpanders.com","avatar":"https://avatars.githubusercontent.com/u/8965202?v=4"},"body":"Hello,\n\nI'm working on standing up a self-hosted git server. I'd like to keep my \nrepositories under a dedicated directory, i.e. /srv/git, but I'd also \nlike to be able to clone a repository using a simple syntax:\n\n     git clone git@myserver:repo.git\n\nas opposed to\n\n     git clone git@myserver:/srv/git/repo.git\n\nI've not yet found a way to get this to work without keeping the \nrepositories in the git user's home folder. I've tried using a ~/.ssh/rc \nfile to chdir into /srv/git and I've tried using the `command=` \nparameter in the authorized_keys file; however, both of these fail \nbecause `cd` is not recognized as a valid command by git-shell.\n\nI suppose I could create symlinks from the repositories in /srv/git into \n/home/git, but I'm wondering if there's a cleaner way to do this?\n\nThanks,\n\nGreg\n"},{"id":"392521","messageId":"241ea912-44b2-96fa-6f9a-3f04d5386b05@gmail.com","threadId":"52886","inReplyTo":"20200226004830.oxd5562v7qqspnkk@Kepler","subject":"Re: git-shell default working directory","fromName":"Andrei Rybak","fromEmail":"rybak.a.v@gmail.com","sentAt":"2020-02-26T09:10:05Z","receivedAt":"2020-02-26T09:10:13Z","isPatch":false,"sender":{"key":"rybak.a.v@gmail.com","avatar":"https://avatars.githubusercontent.com/u/624072?v=4"},"body":"On 2020-02-26 01:48, Greg Anders wrote:\n> Hello,\n\nHi Greg,\n\n> I'm working on standing up a self-hosted git server. I'd like to keep my\n> repositories under a dedicated directory, i.e. /srv/git, but I'd also\n> like to be able to clone a repository using a simple syntax:\n>\n> git clone git@myserver:repo.git\n>\n> as opposed to\n>\n> git clone git@myserver:/srv/git/repo.git\n>\n> I've not yet found a way to get this to work without keeping the\n> repositories in the git user's home folder.\n\nDisclaimer: I'm not at all familiar with git server setup. Would it make sense\nto change git user home directory to be the required dedicated directory?\n\n> I've tried using a ~/.ssh/rc\n> file to chdir into /srv/git and I've tried using the `command=`\n> parameter in the authorized_keys file; however, both of these fail\n> because `cd` is not recognized as a valid command by git-shell.\n>\n> I suppose I could create symlinks from the repositories in /srv/git into\n> /home/git, but I'm wondering if there's a cleaner way to do this?\n>\n> Thanks,\n>\n> Greg \n\n"},{"id":"392565","messageId":"20200226201121.GA287048@coredump.intra.peff.net","threadId":"52886","inReplyTo":"241ea912-44b2-96fa-6f9a-3f04d5386b05@gmail.com","subject":"Re: git-shell default working directory","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-02-26T20:11:21Z","receivedAt":"2020-02-26T20:11:24Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 26, 2020 at 10:10:05AM +0100, Andrei Rybak wrote:\n\n> > I've not yet found a way to get this to work without keeping the\n> > repositories in the git user's home folder.\n> \n> Disclaimer: I'm not at all familiar with git server setup. Would it make sense\n> to change git user home directory to be the required dedicated directory?\n\nYeah, that's what I would suggest. git-shell does explicitly cd to\n$HOME, so any chdir you do before then will be lost (though you could\nperhaps just set $HOME in ~/.ssh/rc).\n\n-Peff\n"},{"id":"392570","messageId":"xmqqeeuhhz3a.fsf@gitster-ct.c.googlers.com","threadId":"52886","inReplyTo":"20200226201121.GA287048@coredump.intra.peff.net","subject":"Re: git-shell default working directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2020-02-26T20:29:13Z","receivedAt":"2020-02-26T20:29:18Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Feb 26, 2020 at 10:10:05AM +0100, Andrei Rybak wrote:\n>\n>> > I've not yet found a way to get this to work without keeping the\n>> > repositories in the git user's home folder.\n>> \n>> Disclaimer: I'm not at all familiar with git server setup. Would it make sense\n>> to change git user home directory to be the required dedicated directory?\n>\n> Yeah, that's what I would suggest. git-shell does explicitly cd to\n> $HOME, so any chdir you do before then will be lost (though you could\n> perhaps just set $HOME in ~/.ssh/rc).\n\nI didn't suggest it because the original request did not sound like\nbuilding a dedicated machine that is used only to push into without\ninteractive shell access.  If $HOME is moved to such a git centric\nplace, that would make it almost impossible to use the account for\nshell interactive access, I would imagine, and if that is acceptable,\nperhaps something like gitolite would fit the bill better?\n"},{"id":"392571","messageId":"20200226203931.GA288832@coredump.intra.peff.net","threadId":"52886","inReplyTo":"xmqqeeuhhz3a.fsf@gitster-ct.c.googlers.com","subject":"Re: git-shell default working directory","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2020-02-26T20:39:31Z","receivedAt":"2020-02-26T20:39:34Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 26, 2020 at 12:29:13PM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > On Wed, Feb 26, 2020 at 10:10:05AM +0100, Andrei Rybak wrote:\n> >\n> >> > I've not yet found a way to get this to work without keeping the\n> >> > repositories in the git user's home folder.\n> >> \n> >> Disclaimer: I'm not at all familiar with git server setup. Would it make sense\n> >> to change git user home directory to be the required dedicated directory?\n> >\n> > Yeah, that's what I would suggest. git-shell does explicitly cd to\n> > $HOME, so any chdir you do before then will be lost (though you could\n> > perhaps just set $HOME in ~/.ssh/rc).\n> \n> I didn't suggest it because the original request did not sound like\n> building a dedicated machine that is used only to push into without\n> interactive shell access.  If $HOME is moved to such a git centric\n> place, that would make it almost impossible to use the account for\n> shell interactive access, I would imagine, and if that is acceptable,\n> perhaps something like gitolite would fit the bill better?\n\nI took the mention of /home/git to mean it was a dedicated \"git\" user.\nBut yeah, that would be an awful suggestion for a regular user. :)\n\nAnd I second the notion of gitolite for a dedicated setup like this (I\nhaven't really used it much myself, but the design always seemed quite\nsane to me).\n\nI _do_ keep git repositories on a host accessible by my normal user.\nIt's a mild inconvenience to have to clone \"git.peff.net:git/foo.git\"\ninstead of just \"git.peff.net:foo.git\". We could allow a config or\nenvironment variable to re-root a relative path given to upload-pack. As\nlong as it was clear this isn't a security feature (it's for people who\nalready have shell access, and could be overridden by an absolute path),\nI think it would be OK.\n\n-Peff\n"},{"id":"392644","messageId":"20200227215715.qzxtbzvirxg3mnqv@Kepler","threadId":"52886","inReplyTo":"20200226203931.GA288832@coredump.intra.peff.net","subject":"Re: git-shell default working directory","fromName":"Greg Anders","fromEmail":"greg@gpanders.com","sentAt":"2020-02-27T21:57:15Z","receivedAt":"2020-02-27T21:57:21Z","isPatch":false,"sender":{"key":"greg@gpanders.com","avatar":"https://avatars.githubusercontent.com/u/8965202?v=4"},"body":"Thanks for the replies everyone!\n\n>Disclaimer: I'm not at all familiar with git server setup. Would it \n>make sense to change git user home directory to be the required \n>dedicated directory?      \n\nI did think about this but that doesn't really solve the problem. The \nreason I'd like to use a dedicated directory for the repositories is so \nthat I can separate the repos from the git user's home files (e.g.  \n.profile, .ssh, etc.) I am also hosting an HTTP front end that reads the \nrepos and I don't want to introduce a security risk by giving the web \nserver access to the git user's home directory.\n\n>Yeah, that's what I would suggest. git-shell does explicitly cd to\n>$HOME, so any chdir you do before then will be lost (though you could\n>perhaps just set $HOME in ~/.ssh/rc).\n\nI did try ~/.ssh/rc, but when using git-shell it says `/bin/sh .ssh/rc: \nUnknown command` or something to that effect. I'm assuming this has to \ndo with the fact that git-shell can only run a certain subset of \ncommands (although according to the SSH docs, the rc file _should_ be \nexecuted _before_ switching to the user's $SHELL, so I'm not actually \nquite sure why this doesn't work).\n\n>And I second the notion of gitolite for a dedicated setup like this (I\n>haven't really used it much myself, but the design always seemed quite\n>sane to me).\n\nI'd actually never heard of gitolite before. It does look like a great \npiece of software, but I'm worried it might be overkill for me since I'm \nrunning just a single-user setup (i.e. me).\n\nFor now, I've just created symlinks from /srv/git into /home/git which \nallows cloning over SSH to work how I'd expect. I also created a \ninteractive command under git-shell-commands/ that will create a new \nrepository in /srv/git and also automatically generate the symlinks into \n/home/git. It feels a bit hacky, but it works!\n\n"},{"id":"392689","messageId":"20200228204013.xihhlduk7sl4egvx@Kepler","threadId":"52886","inReplyTo":"20200227215715.qzxtbzvirxg3mnqv@Kepler","subject":"Re: git-shell default working directory","fromName":"Greg Anders","fromEmail":"greg@gpanders.com","sentAt":"2020-02-28T20:40:13Z","receivedAt":"2020-02-28T20:40:43Z","isPatch":false,"sender":{"key":"greg@gpanders.com","avatar":"https://avatars.githubusercontent.com/u/8965202?v=4"},"body":"Just wanted to follow up one more time on this: I decided to give \ngitolite a look and am extremely impressed! It was quite easy to set up \nand does exactly what I want and quite a bit more!\n\nJust wanted to provide a glowing recommendation for anyone else \nconsidering doing their own git hosting.\n\nGreg\n"}]}