remote git repo is actually no difference from a local one. Here’s how to setup a LOCAL git server.
- 1. Install Git
- 2.Add a “git” user
- 3. Create SSH Certified Login
- 4. Initialize a Git Repo
- 5. Ban the Shell Login (Optional)
- 6. Clone Remote Repository
- 7. Git Remote
- Reference:
1. Install Git
After setting up a linux system, e.g. Ubuntu server 16.06, install git:
sudo apt-get install git
2.Add a “git” user
Create a git user by:
sudo adduser git
3. Create SSH Certified Login
Collect all the public keys of possible users/machines (in their id_rsa.pub
respectively). Put all the collected public keys in file /home/git/.ssh/authorized_keys
.
- e.g. on a remote server, type
ssh-copy-id git@[you-git-server-ip-address]
to automatically add the current server’s public key to theauthorized_keys
of the git server.
4. Initialize a Git Repo
After logging in with git
, select a folder, e.g. /home/sample
, cd
into this folder and type:
sudo git init --bare sample.git
With the command above, Git will generate a bare repository.
Since the Git repo on this server only aim for sharing, it doesn’t allow other users to login into the server and make changes. Therefore, we should set the owner:group of the repo as git
:
sudo chown -R git:git sample.git
5. Ban the Shell Login (Optional)
Based on the security concern, our git account is not supposed to allow SSH login. So we can acheive this by modifying /etc/passwd
file, in which we may find:
git:x:1001:1001:,,,:/home/git:bin/bash
we change this to:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
6. Clone Remote Repository
Now we are able to clone remote git repo(s) on you local computer by:
git clone git@[you-git-server-ip]:sample/sample.git
7. Git Remote
On the remote computer, just try pull/push etc. to use the remote repository.
7.1 How to upload a local directory to remote repo
Reference:
KF