文章目录
  1. 1. Create git user
  2. 2. Add ssh key for client user
  3. 3. Create new git repository
  4. 4. Prevent SSH login of git user
  5. 5. Done

Create git user

1
2
3
4
5
$ sudo adduser git
$ su git
$ cd
$ mkdir .ssh && chmod 700 .ssh
$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

Add ssh key for client user

1
$ cat /tmp/id_rsa.pub >> ~/.ssh/authorized_keys

Create new git repository

1
2
3
4
$ mkdir -p /opt/git/project.git
$ cd /opt/git/project.git
$ git init --bare
Initialized empty Git repository in /opt/git/project.git/

Prevent SSH login of git user

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

Done

1
2
$ git clone git@gitserver:/opt/git/project.git
$ cd project

文章目录
  1. 1. Create git user
  2. 2. Add ssh key for client user
  3. 3. Create new git repository
  4. 4. Prevent SSH login of git user
  5. 5. Done