Saturday, July 2, 2016

How to Setup Git Server on Mac OS X

In this tutorial, I will go over the instructions to setup a git server on Mac OS X. Here, I will assume that the server IP address is 12.34.56.78.

First, you will need to add a user named git, into which client machines will ssh into. To do so,
1. Open up System Preferences -> Users & Groups
2. You may need to click the Lock image to make any changes. 
3. Click on the + button to add a user.
4. Add a standard user whose full name and account name is git. Enter password.
5. Click on Create User button.

Next, you will need to allow ssh login for user git from client machines. To do so,
1. Open up System Preferences -> Sharing
2. Check Remote Login box.
3. Add the user git in the Allow access for field by clicking on the + button.

From your client system, make sure that you can remote log into the server's git account.
$ ssh git@12.34.56.78 -p 22

Note that here I am assuming that you are using the port 22 to access the server. Depending on your router or firewall configuration, the port number may differ.

If you can successfully log into the account, then you are pretty much done. Let's assume that you will want to create a repository named Project. From the git account from the server or through ssh, run
$ pwd
/Users/git
$ git init --bare Project.git

This will create a bare Project repository on the server, which clients can clone, push to, and pull from. The location of this repository in this case is /Users/git/Project.git, as you can see from pwd command above. To clone this repository from a client, you will need to run the following from the client
$ git clone ssh://git@12.34.56.78:22/Users/git/Project.git

You will need to enter the password for the server's git account, as if you are remote logging into it through ssh. You should now have a personal git server.

Note: If you are concerned with safety, you may want to disable password login and instead only allow public key authentication. I will cover how to do so in the future post.

6 comments:

  1. Replies
    1. Well, I don't use Source Tree, but from Google search, this may help you: https://confluence.atlassian.com/bitbucket/set-up-an-ssh-key-728138079.html#SetupanSSHkey-ssh3SetupSSHwithSourcetreeonWindows

      Delete
  2. Four years later - still relevant.

    ReplyDelete