Sunday, October 4, 2015

Set up git server on ubuntu

On server:
1
2
3
4
5
6
sudo apt-get install git
sudo adduser git
su git
cd
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

On workstation:
1
2
3
sudo apt-get install git
ssh-keygen -t rsa -C "yourname@mail.com"
scp .ssh/id_rsa.pub git@gitserver:/tmp

On server:
1
2
3
4
5
6
7
sudo mkdir /opt/git
cd /opt
sudo chown git git
cd git
mkdir project.git
cd project.git
git init --bare

On workstation:
1
2
3
4
5
6
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin git@gitserver:/opt/git/project.git
git push origin master

On server: (prevent using git to log on)
1
2
3
4
cat /etc/shells   # see if `git-shell` is already in there.  If not...
which git-shell   # make sure git-shell is installed on your system.
sudo vim /etc/shells  # and add the path to git-shell from last command
sudo chsh git  # and enter the path to git-shell, usually: /usr/bin/git-shell


Reference:
https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
https://help.ubuntu.com/lts/serverguide/git.html

No comments:

Post a Comment