Build notes for GIT servers

Source: Internet
Author: User

Ubuntu System selected for server system

Build steps:
1. Install git
sudo apt-get install git


2. Create a git user and run the GIT service
sudo adduser git


3. Create a certificate Login
Collect all the user's public key to log in, that is, id_rsa.pub file, import all the public key into the/home/git/.ssh/authorized_keys file, one line at a.
CD git
mkdir. SSH
CD. SSH
Touch Authorized_keys
Next, add the developer's SSH public key to the user's Authorized_keys file.

How do I find my own public key?
User home directory, see if there is. SSH, if there is, then look at this directory there are no Id_rsa and id_rsa.pub these two files, if already have, can jump directly to the next step.
If not, open the shell (open git Bash under Windows) and create SSH Key:
Ssh-keygen-t rsa-c "[Email protected]"
If all goes well, you can find the. SSH directory in the user's home directory, there are Id_rsa and id_rsa.pub two files, these two are SSH key key pair, Id_rsa is the private key, can not be leaked out, Id_rsa.pub is the public key, can be assured to tell anyone.

Note: When creating SSH key, there is a hint to tell you where the public key is located:



4. Initializing the Git repository
Select a directory as the Git repository, assuming/srv/sample.git, enter the command in the/SRV directory:
sudo git init--bare sample.git
Git creates a bare repository with no workspaces, because the GIT repository on the server is purely for sharing, so you don't let users log on to the server directly to the workspace, and the Git repositories on the server usually end up with. Git. Then, change owner to git:
sudo chown-r git:git sample.git


5. Disable Shell Login

for security reasons, the GIT user created in the second step is not allowed to log in to the shell, which can be done by editing the/etc/passwd file. Find a line similar to the following:

git:x:1001:1001:,,,:/home/git:/bin/bash
Switch
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
In this way, git users can use git normally via SSH, but cannot log in to the shell because the Git-shell we specify for git users automatically exits every time a login is logged in.


6. Push a branch to upload the first version of the project to the warehouse.

in the PC:
mkdir MyProject
CD MyProject
Git init
Touch Readme
Git add Readme
git commit-m ' initial commit '
git remote add origin [email protected]:/srv/sample.git
Git push Origin Master

In this way, your project is pushed to the remote repository.


if the other members of a group edit the project together, simply add his or her public key and copy the project:
git clone [email protected]:/srv/sample.git
You can work together, but note that you should git pull before each push project.



problems encountered:
1) error:src Refspec Master does not match any.
Error:failed to push some refs to ' [email protected]:/srv/sample.git '
Cause: There is no file in the directory, the empty directory cannot be submitted up
2) Git remote add origin [email protected]:/srv/sample.git
Fatal:remote origin already exists.
Operation error, remote warehouse wrong, how to remove the remote warehouse:
Git remote RM Origin

Build notes for GIT servers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.