Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to build your own git server management website

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you how to build your own git server management website related knowledge, detailed content, clear logic, I believe that most people still know too much about this knowledge, so share this article for your reference, I hope you can learn something after reading this article, let's take a look at it.

The topology looks like this:

WS, the website server, is the server of this site that you see. The main thing we need to do on WS is git server configuration.

DS, the development server, is to find other servers. The main thing to do on DS is to configure the git local environment

The local computer PC is the computer that writes the code.

In other words, the expected correct operation is: PC develops the code with PhpStorm, submits it to the development server with its own ssh submission function, and DS provides web preview to preview the effect in a timely manner. When the effect is stable, use git to submit to the website server to complete the functional iteration. At the same time, git can also do version control, and I'm a little excited to think about it.

List of related versions:

Machine software version of WS/DS operating system Debian 8.2WS/DSgit2.1.41, WS: add 163Source of apt

The source here is the source provided by 163for Debian 8 (Jessie). You can find the source suitable for your version, Tsinghua University image source, and so on.

Vi / etc/apt/sources.list

Join:

Deb http://mirrors.163.com/debian/ jessie main non-free contribdeb http://mirrors.163.com/debian/ jessie-updates main non-free contribdeb http://mirrors.163.com/debian/ jessie-backports main non-free contribdeb-src http://mirrors.163.com/debian/ jessie main non-free contribdeb-src http://mirrors.163.com/debian/ jessie-updates main non-free contribdeb-src http://mirrors.163.com/debian/ jessie-backports main non -free contribdeb http://mirrors.163.com/debian-security/ jessie/updates main non-free contribdeb-src http://mirrors.163.com/debian-security/ jessie/updates main non-free contrib2, Install git and sudoapt-get install gitapt-get install sudo3 under WS:root users and add user adduser bwb for git under WS:root users

The password must be entered, this password is the password to log on to this account.

4. WS:root user gives bwb user sudo permission vi / etc/sudoers

Add:

Bwb ALL= (ALL:ALL) ALL

And use wq! To make a forced save.

5. DS: create the key of ssh cd ~ / .sshssh-keygen-t rsa

You will be prompted for a password, which is the password of the key. It is recommended that you enter it (although you can succeed without entering it). If you don't have a .ssh directory, you can create one manually.

6. DS → WS: copy id_rsa.pub

You can use ftp tools like xftp4 to copy the generated id_rsa.pub from DS to WS. If you use xftp4, notice that you can see the hidden directory .ssh by checking "Show Hidden Files" through the tool → option in the menu bar.

7. WS: configure ssh

Enter from root users (or directly from bwb users):

Su bwbsudo mkdir ~ / .sshsudo cd ~ / .sshsudo cat id_rsa.pub > > authorized_keyssudo service ssh restart

(1) create .ssh if there is no .ssh.

(2) the id_rsa.pub here should fill in the path of the file you copied.

(3) after the configuration is completed, you can use the following method on DS:

Touch test.txtscp-r test.txt bwb@xxx.xxx.xxx.xxx:/home/bwb

To see if test.txt has been copied to the / home/bwb directory on WS. The xxx.xxx.xxx.xxx here is the IP of WS. Of course, you can also fill in the domain name of the URL.

8. Configure git server under WS:bwb user

We assume that the directory of the web project is / home/testweb.

(1) enter the directory

Cd / home/testweb

(2) initialize empty warehouse

Git init

Will prompt:

Initialize the empty Git version library in / home/testweb/.git/

(3) modify config

Vi .git / config

Join:

[receive] denyCurrentBranch = ignore

(4) modify hook

Create a new hook

Vi. Git/hooks/post-receive

Join:

#! / bin/shGIT_WORK_TREE=/home/testweb git checkout-f

(5) join README.md

Touch README.md

(6) add all the documents under the project to git

Git add.

Pay attention to the back spot.

(7) submit to local warehouse

Git commit-m "Initial commit" 9, DS: configure local git

(1) installation environment

Consistent with the previous operation of configuring the source and installing git, only these two steps are needed.

(2) cloning project:

Git clone bwb@xxx.xxx.xxx.xxx:/home/testweb

You will be prompted for a password, which is the password of the previously set id_rsa.

(3) [optional] create robot.txt to prohibit crawling all files:

Vi robot.txt

Join:

User-agent: * Disallow: /

(4) [optional] rules for creating files that you do not want to upload:

Vi .gitignore

Join:

# self/.gitignore#robotrobot.txt

(5) whether the test is successful or not

Echo "123" > > README.mdgit add .git statusgit commit-m" test "git push

Git status is to check what is to be submitted before submitting, and you don't need this command.

10. Restrict the permissions of the bwb account

If the previous one is successful, it will be almost finished. This is just for more security to restrict the permissions of bwb. You can only git, you cannot log in, and you cannot use sudo to raise rights:

(1) modify shell permissions

Vi / etc/passwd

Put:

Bwb:x:1000:1000:,:/home/bwb:/bin/bash

Change to:

Bwb:x:1000:1000:,:/home/bwb:/usr/bin/git-shell

(2) modify sudo permissions

Vi / etc/sudoers

Add the previously added:

Bwb ALL= (ALL:ALL) ALL

Comment out with #:

# bwb ALL= (ALL:ALL) ALL

Pay attention to using wq! Forced save, congratulations, the building is complete.

1. Why does WS add denyCurrentBranch = ignore to config?

Because if you don't add it, DS will report an error when push, to the effect that it is not a naked warehouse:

Remote: error: refusing to update checked out branch: refs/heads/masterremote: error: By default, updating the current branch in a non-bare repositoryremote: error: is denied, because it will make the index and work tree inconsistentremote: error: with what you pushed, and will require 'git reset-- hard' to matchremote: error: the work tree to HEAD.remote: error:remote: error: You can set' receive.denyCurrentBranch' configuration variable toremote: error: 'ignore' or' warn' in the remote repository to allow pushing intoremote: error: its current branch However, this is not recommended unless youremote: error: arranged to update its work tree to match what you pushed in someremote: error: other way.remote: error:remote: error: To squelch this message and still keep the default behaviour, setremote: error: 'receive.denyCurrentBranch' configuration variable to' refuse'.2, why did WS add that hook?

Because if you do not add hook, DS push,WS will not see the results, because the worktree has not been updated. You can see the difference by using git status on WS, which stays on the master branch all the time. The workaround is to update manually:

Git reset-hard

But this is too troublesome, so add hook, and if you add it, it will be updated automatically. Hook means "what if does, then does what it does." it helps you finish it.

3. Why not use git init-bare?

This is a question that I have studied and practiced for a long time, and the answer is,-- bare is not suitable for web code management.

(1) appearance

First, let's take a look at the appearance difference between git init-bare (hereinafter referred to as bare) and git init (hereinafter referred to as init):

Init creates a hidden folder of .git with branches, config, description, HEAD, hooks, info, objects, refs

Instead of creating a .git folder, bare creates the same content directly under the current folder.

(2) function

Init can perform git operations on the git server

Bare cannot perform git operations on the git server, it will report an error: This operation must be run in a work tree

(3) essence

The essence of init is to create a working directory, while the essence of bare is to record only historical information and not maintain the working directory.

Therefore, init is suitable for the maintenance of web projects, and the updated complete web project files can be seen in real time on WS. Bare is suitable for multi-person project maintenance. You don't need to see the updated working directory in the remote warehouse, you just need to record what everyone has done. If you maintain a web project with bare, WS will not respond after DS push (of course, the objects file will be updated, but other files will not respond), and no git operation can be performed on WS. So you should use init.

4. I updated .gitignore. How do I make it work again? Git add. / / resubmit the .submission file git rm-r-- cached. / / clear the cache git add. / / resubmit all files git commit-m "update .gitignore" git push

Pay attention to the points in the command.

5. I created a new user by mistake. How do I undo it? Userdel-r bwb

Bwb is for users you don't want to create.

6. Failed in git clone: Host key verification failed

Tip:

Are you sure you want to continue connecting (yes/no)? Host key verification failed.fatal: Could not read from remote repository.

This is because you enter enter instead of "yes". Just type yes.

7 、 Please tell me who you are?

Follow the prompts to set up config:

Git config-global user.email "you@example.com" git config-global user.name "Your Name"

Its essence is to modify the .git / config file.

8. Ssh connection prompt Permission denied (publickey)?

First, check whether you have permissions for that file (for example, it is a folder that can only be accessed by root users). If not, please grant permission:

Chown-R bwb:bwb home/testweb

Then check to see if the contents of DS's id_rsa.pub are successfully added to WS's authorized_keys.

In the end, it is very likely that you have the wrong user. For example, if you assign the id_rsa.pub of DS to the authorized_keys of the root user of WS, and the ssh you visit later is the bwb user, of course, it is rejected.

If not, the debian operating system can check / var/log/auth.log, other operating systems can check / var/log/secure, and then:

Tail-N100 / var/log/auth.log | grep sshd

To see if the connection has been made and what went wrong.

9. The common syntax of .gitignore # ignore files test.txt# ignores files in the root directory / test.txt# ignores files in the specified directory / src/test.txt# ignores directories / test# ignores folders, but does not ignore some of the files / test.txt10, robot.txt common syntax

Robot.txt online generation

The robot.txt of the brief book

Iqiyi's robot.txt

The simplest configuration:

User-agent: * here * represents all kinds of search engines, * is a wildcard Disallow: / defined here is forbidden to crawl all the content of the site, which is all the content of the article "how to build your own git server to manage the website". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report