Project

General

Profile

Feature #87

Set Up Local Git Respository on Debian/Ubuntu

Added by Daniel Curtis over 11 years ago. Updated over 10 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
-
Target version:
-
Start date:
03/02/2013
Due date:
% Done:

100%

Estimated time:
0.50 h
Spent time:

Description

Setup the client

Start by creating a new SSH key pair:

ssh-keygen -t ecdsa

And then set the clients information:

git config --global user.email "user@example.com" 
git config --global user.name "John Doe" 

Set up the server

These instructions were performed on a Debian system, so assume them to be the same on Ubuntu. Substitute the package installation commands as required if you’re on an alternative distribution.

Add your public key to the server:

ssh myuser@server.com mkdir .ssh
scp ~/.ssh/id_ecdsa.pub user@example.com:.ssh/authorized_keys

SSH into our server and install Git:

ssh example.com
sudo apt-get update
sudo apt-get install git-core

Adding a user

If you intend to share these repositories with any collaborators, at this point you’ll either:

We’ll be following the latter option. Add a Git user:

sudo adduser git

Now you’ll need to add your public key to the Git user’s authorized_keys:

sudo mkdir /home/git/.ssh
sudo cp ~/.ssh/authorized_keys /home/git/.ssh/
sudo chown -R git:git /home/git/.ssh
sudo chmod 700 /home/git/.ssh
sudo chmod 600 /home/git/.ssh/*

Now you’ll be able to authenticate as the Git user via SSH. Test it out:

ssh git@example.com

Add your repositories

If you were to not share the repositories, and just wanted to access them for yourself (like I did, since I have no collaborators), you’d do the following as yourself. Otherwise, do it as the Git user we added above.

If using the Git user, log in as the git user:

login git

Now create the repositories:

mkdir myrepo.git
cd !$
git --bare init

The last steps creates an empty repository. We’re assuming you already have a local repository that you just want to push to a remote server.

Repeat that last step for each remote Git repository you want.

Log out of the server as the remaining operations will be completed on your local machine.
Configure your development machine

First, we add the remotes to your local machine.

If you’ve already defined a remote named origin (for example, if you followed GitHub’s instructions), you’ll want to delete the remote first:

git remote rm origin

Add the new remote:

git remote add origin git@server.com:myrepo.git
git push origin master

You’ll probably also want to make sure you add a default merge and remote:

git config branch.master.remote origin && git config branch.master.merge refs/heads/master

Now you can push/pull from origin as much as you like, and it’ll be stored remotely on your own example.com remote repository.

Move SSH to a different port

This has been extensively covered by the excellent Slicehost tutorial , but just to recap:

Edit the SSH config and change the following values:

sudo vi /etc/ssh/sshd_config

Port 2207
...
PermitRootLogin no
...
AllowUsers myuser git
...
PasswordAuthentication no

Where 2207 is a port of your choosing. Make sure to add this so your Git remote:

git remote add origin ssh://git@example.com:2207/myrepo.git

#1

Updated by Daniel Curtis over 10 years ago

  • Description updated (diff)

Also available in: Atom PDF