Series of articles


Table of Contents

  • Series of articles
  • preface
  • operation
    • 1. Create a Git user
    • 2. Create the.ssh directory
    • 3. Customize the root directory of the warehouse
    • 4. Create a bare repository on the server
    • 5. Manually configure a public key
    • 6. Check whether the operation can be performed locally
  • conclusion

preface

How to build a Git Server with GitHub, GitLab, Gitee, etc

operation

Note: this example is a git service set up on a cloud server, where 1,2,3,4,5 are all performed on the cloud server. You can also do this in a virtual machine or docker

1. Create a Git user

adduser \
   --system \
   --shell /bin/bash \
   --gecos 'Git Version Control' \
   --group \
   --disabled-password \
   --home /home/git \
   git
Copy the code

2. Create the.ssh directory

/home# su git
/home# cd git
/home/git# mkdir .ssh && chmod 700 .ssh
/home/git# touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
Copy the code

3. Customize the root directory of the warehouse

/home/git# mkdir code_repository
Copy the code

Note: You need to use the Git user to do this

4. Create a bare repository on the server

/home/git# cd code_repository/
/home/git/code_repository# mkdir abc.git
/home/git/code_repository# cd abc.git/
/home/git/code_repository/abc.git# git init --bare
Copy the code

Note: You need to use the Git user to do this

5. Manually configure a public key

To add our own local public key file/home/git /. SSH/authorized_keys

6. Check whether the operation can be performed locally

$ mkdir abc
$ cd abc
$ git init
$ touch README.md
$ git add .
$ git commit -m "first add reademe.md"
$ git remote add origin ssh://[email protected]:/home/git/code_repository/abc.git
$ git push -u origin master
Copy the code

Note: this is running locally, not on the server

conclusion

The repository is created in this way without setting any permissions, and only the public key user in authorized_keys can read and write to the repository

reference

  • git-scm