If you don’t want to upload your code to Github or the code cloud, building your own Git server is a good choice.
The preparatory work
First, you need a Linux cloud server. Ubuntu is recommended. Installing Git is very simple. You need to have an account with sudo permission, usually root
Install Git
sudo apt-get install git
Copy the code
Creating a Git user
Used to run git services
sudo adduser git
Copy the code
Create a certificate to avoid secret login
Create the local public key
ssh-keygen -t rsa
Copy the code
SSH /, you will see two newly created files, id_rsa.pub and id_rsa. One is the public key and the other is the private key. Log in to the SSH server as the newly created user and open the /home/git directory on the server. In this case, the root directory of the newly created user has not been created. After you have created the.ssh directory, go to CD and touch authorized_keys to create the authorized_keys file, which is used to record the client’s public key for secret free login. Copy the contents of the public key you created on the client side to authorized_keys, then save and exit.
Initialize the Git repository for testing
Let’s say you’re in the /home/git directory
git init --bare demo.git
Copy the code
A demo.git directory appears, and you change the directory permissions and owner
sudo chown -R git:git demo.git
Copy the code
Clone Git repository locally
git clone [email protected]:/home/git/demo.git
Copy the code
This time is arguably should not enter the password, cloned directly, without success, that on the server/home/git /. SSH and/home/git /. SSH/authorized_keys wrong permissions.
- SSH directory permissions must be 700 **
- SSH /authorized_keys file permission must be 600
Change the permissions sudo chmod -r 700 / home/git /. SSH, sudo chmod 600 / home/git /. SSH/authorized_keys
You can then submit the code to test if it works.