In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly explains "CentOS how to build Git server". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian slowly and deeply to study and learn "CentOS how to build Git server" together!
Check if the server has git installed.
[root@iz25r8k6ifuz git]# rpm -qa gitgit-1.7.1-3.el6_4.1.x86_64
It has been installed here, if not installed, you can install it with yum install git.
2. Create a git user
Here you can choose to create a new user to test, or you can use your root to do the following. The author is also looking at the information step by step, here to create a new user teslachen operation.
[root@iz25r8k6ifuz ~]# useradd tesla[root@iz25r8k6ifuz ~]# passwd tesla
Change the password for user tesla.
New password:
Invalid password: it does not contain enough different characters
Invalid password: too simple
Re-enter the new password:
passwd: All authentication tokens have been successfully updated.
Note 1: Please add sudo if the permission to create user is not enough;
Note 2: If setting the user password is too simple, there will be a prompt, but it can still be set successfully.
3. Generate SSH public key
Many git servers use ssh public keys for authentication. In order to provide the git server with the ssh public key, a copy must be generated for a system user if he or she does not already own the key.
Linux can run ssh-keygen -t rsa natively to generate keys and copy.pub files to the server.
[root@iz25r8k6ifuz ~]# su tesla[tesla@iz25r8k6ifuz root]$ cd ~[tesla@iz25r8k6ifuz ~]$ mkdir .ssh[tesla@iz25r8k6ifuz ~]$ ssh-keygen -t rsagenerating public/private rsa key pair.enter file in which to save the key (/home/tesla/.ssh/id_rsa):enter passphrase (empty for no passphrase):enter same passphrase again:your identification has been saved in /home/tesla/.ssh/id_rsa.your public key has been saved in /home/tesla/.ssh/id_rsa.pub.the key fingerprint is:13:bf:75:ba:67:7f:0e:a0:47:7a:fe:25:bc:81:85:c3 tesla@iz25r8k6ifuzthe key's randomart image is:+--[ rsa 2048]----+| || || . || o . . || s . e o || . o || + = = .|| + .o.|| o+oo+|+-----------------+[tesla@iz25r8k6ifuz ~]$ cd .ssh/[tesla@iz25r8k6ifuz .ssh]$ cat id_rsa.pub >> ~/.ssh/authorized_keysexit
Add tesla to sudoers file
The tesla user does not have permissions on some folders now, modify the/etc/sudoers file to change his permissions. The top administrator user opens with the following command.
[root@iz25r8k6ifuz ~]# visudo
Then we find the following line in vim
root all=(all) all
Press the i key to insert, press Enter and add
tesla all=(all) all
Then press esc key, type:wq, enter save exit
5 Create a git code repository
[root@iz25r8k6ifuz ~]# mkdir /teslarepo[root@iz25r8k6ifuz ~]# cd /teslarepo/[root@iz25r8k6ifuz teslarepo]# sudo mkdir teslaproject.git[root@iz25r8k6ifuz teslarepo]# chown tesla:tesla /teslarepo/[root@iz25r8k6ifuz teslarepo]# chown -r tesla:git /teslarepo/[root@iz25r8k6ifuz teslarepo]# cd teslaproject.git/[root@iz25r8k6ifuz teslaproject.git]# sudo git --bare initinitialized empty git repository in /teslarepo/teslaproject.git/
So a git repository called teslaproject is created
Six Local Test Uses
You can test it locally directly on the server, or you can test it directly on your computer. Below is my test using my mbp.
localhost:~ okay$ cd desktop/git/localhost:git okay$ mkdir teslarepolocalhost:git okay$ cd teslarepo/localhost:teslarepo okay$ git initinitialized empty git repository in /users/okay/desktop/git/teslarepo/.git/localhost:teslarepo okay$ git remote add origin tesla@123.57.159.74:/teslarepo/teslaproject.git
The above command creates a folder locally and adds a remote repository on the server
localhost:teslarepo okay$ touch a.txtlocalhost:teslarepo okay$ git add a.txtlocalhost:teslarepo okay$ git commit -m "init commit"[master (root-commit) d14cd3b] init commit 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 a.txt
The above command creates an a.txt locally and commits it locally once
localhost:teslarepo okay$ git push origin mastertesla@123.57.159.74's password:counting objects: 3, done.writing objects: 100% (3/3), 202 bytes | 0 bytes/s, done.total 3 (delta 0), reused 0 (delta 0)to tesla@123.57.159.74:/teslarepo/teslaproject.git * [new branch] master -> master
The above command pushes the local code to the remote server. Let's see if it's correct once in the local clone.
7 local clones
localhost:git okay$ mkdir tttlocalhost:git okay$ cd tttlocalhost:ttt okay$ git clone tesla@123.57.159.74:/teslarepo/teslaproject.gitcloning into 'teslaproject'... tesla@123.57.159.74's password:remote: counting objects: 3, done.remote: total 3 (delta 0), reused 0 (delta 0)receiving objects: 100% (3/3), done.checking connectivity... done.
clone done, let's look at the folder directory
The a.txt file previously pushed onto the server has been cloned down
------
1. View System User Groups
-d: Specify the field separator, the default field separator is "tab";
-f: Display the contents of the specified field;
cut -d: -f1 /etc/group
2. View System Users
cut -d: -f1 /etc/passwd
3. clone warehouse
git clone git@your_gitserver_ip:/home/gitrepo/sample.git
4. push already has a warehouse
//master branch demonstration git checkout mastergit remote rm originit remote add origin git@your_gitserver_ip:/home/gitrepo/sample.gitgit push -u origin master Thank you for reading, the above is "CentOS how to build Git server" content, after learning this article, I believe you have a deeper understanding of CentOS how to build Git server this problem, the specific use needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.