A small tutorial for how to set up Git Server on Mac OS X. The main dificulty was to create a "system" user (aka "daemon", uid<=500) and allow ssh login for it.
- I need 'git'-user to be system - not visible in standart users list.
- I need to allow ssh access only for some users/groups.
The tutorial for Git server setting up - http://git-scm.com/book/ca/Git-on-the-Server-Setting-Up-the-Server
So I need to create system user 'git' with homefolder.
System user creation script - http://serverfault.com/a/532860. I've modified it a little and uploaded here https://gist.github.com/mwf/20cbb260ad2490d7faaa#file-create_sys_user-sh.
sudo ./create_sys_user.sh git
sudo mkdir /Users/_git
sudo chown _git:_git /Users/_git
After that you can switch user to 'git' and add users public keys as said in Git tutorial.
Now the point of this gist - how to allow SSH for 'git' user.
First, open up System Preferences » Sharing and turn on Remote Login (this is ssh). As you can see - you can't just add 'git' user to access list, cause it's invisible. Here is the hack, based on http://superuser.com/a/166219:
sudo dscl . append /Groups/com.apple.access_ssh GroupMembership git
sudo dscl . append /Groups/com.apple.access_ssh groupmembers `dscl . read /Users/git GeneratedUID | cut -d " " -f 2`
Bingo, you can test the ssh connection to the server (if you've already set up your public key):
ssh git@server-ip
Some usefull stuff:
- If you don't care if 'git' should be system user - just use this guide: http://www.tomdalling.com/blog/software-processes/how-to-set-up-a-secure-git-server-at-home-osx/
- This can be also usefull - https://github.com/sitaramc/gitolite. Found this reference here: http://automatica.com.au/2011/01/setup-git-server-on-mac-osx-server/
Hi! The script is great. Thanks for that. But it asks me a password to connect with git user (
su git
). I tried '*' or empty password but doesn't work. It could have changed since 2014 with macOs Catalina. Should I try with any password or it shouldn't ask any password?Thanks,
Tomy