linuxgit服务
1. linux搭建git远程仓库
1. linux和windows端分别安装git,其中linux中可以用yum安装
[root@node0~]#yum install git
git的默认安装路径在/usr/libexec/git-core
[root@node0 git-core]#cd /usr/libexec/git-core
[root@node0 git-core]#git --version
git version 1.7.1
2.设置linux端git的用户名和密码
[root@node0 git-core]# groupadd git
[root@node0 git-core]# useradd wang -g git
[root@node0 git-core]# passwd wang
New password:
3.在服务器端创建远程仓库
[root@node0 ~]# mkdir -p /mnt/gitrep/wjf
[root@node0 ~]# cd /mnt/gitrep/wjf/
[root@node0 wjf]# git init
Initialized empty Git repository in /mnt/gitrep/wjf/.git/
把仓库所属用户改为wang(git的用户名)
[root@node0 wjf]# chown -R wang:git .git/
注:chown将指定文件的拥有者改为指定的用户或组 -R处理指定目录以及其子目录下的所有文件
4.在windows客户端克隆仓库
$ git clone [email protected]:/mnt/gitrep/wjf/.git
Cloning into 'wjf'...
The authenticity of host '192.168.111.60 (192.168.111.60)' can't be established.
RSA key fingerprint is SHA256:MgWCWF************************1m2tI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.111.60' (RSA) to the list of known hosts.
[email protected]'s password:
第一次连接远程仓库,出现黑体部分,这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,键入yes,然后输入远程仓库的密码就可以了。
5.实际中也通常通过设置公钥的方式来连接远程仓库,这样就不用每次连接都需要密码了。
设置公钥:
1.在windows客户端的gitbash中生成用户私钥和公钥
$ ssh-keygen -t rsa -C "[email protected]"
在c盘用户路径下的/.ssh文件夹下会生成私钥id_rsa和公钥id_rsa.pub
2.linux端
首先 Git服务器打开RSA认证,即,修改/etc/ssh/sshd_config,将其中的以下三项打开
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
然后,将客户端生成的公钥给到服务器端
即,将公钥给到 home/wang(git的用户名)/.ssh/authorized_keys
[root@node0 ~]# cd /home/wang
[root@node0 wang]# mkdir .ssh
[root@node0 wang]# chmod 777 .ssh
[root@node0 wang]# touch .ssh/authorized_keys
在windows客户端的gitbash中 执行:
$ ssh [email protected] 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub
然后在linux端:
[root@node0 wang]# chmod 600 .ssh/authorized_keys
[root@node0 wang]# chmod 700 .ssh
[root@node0 wang]# chown wang:git .ssh
[root@node0 wang]# chown wang:git .ssh/authorized_keys
至此,以后再连接远程仓库就不需要密码了。
若仍需要密码,可以查看ssh连接日志/var/log/secure:
常见连接失败原因:Authentication refused: bad ownership or modes for directory /home/wang/.ssh
这时需要检查该目录的所属用户和读写权限等级是否符合要求。公钥以及.ssh文件的权限应该属于git的用户和用户组,读写权限等级.ssh 700,authorized_keys 600.
2. 如何在 Linux 上安装 git 服务
1、yum方式安装
# yum -y install git
如果提示系统提示没有找到git包,可以采用下面的方式
2、下载Git源码包
官网:http://git-scm.com/
$ tar -xjvf git-1.7.4.1.tar.bz2
$ cd git-1.7.4.1/
$ make prefix=/usr/local all
$ make prefix=/usr/local install
3. 如何在 Linux 上安装 git 服务
1、yum方式安装
# yum -y install git
如果提示系统提示没有找到git包,可以采用下面的方式岩碧悉
2、下载Git源码包粗乎
$ tar -xjvf git-1.7.4.1.tar.bz2
$ cd git-1.7.4.1/
$ make prefix=/usr/local all
$ make prefix=/usr/慧颤local install
4. 如何在 Linux 上安装 git 服务
安装Optware IPKG。这个在QNAP官方的App Center里有提供,直接去安装即可。
安装Git。这里通过ipkg安装的Git比较新。官方App Center里提供的git版本比较老。通过SSH登陆admin账号后运行如下命令。
ipkg update
ipkg install git
初始化git服务器端仓库。你的git仓库务必存放在非系统自带的目录下,否则系统重启之后数据会被抹掉(我尝试了是这样的)。假定服务器端git仓库目录为:/opt/repos,项目目录为hets.git。通过SSH登陆admin账号后运行如下命令。
5. 如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do
然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@linuxprobe ~]# mkdir linuxprobe.git
修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/
初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#
初始化下Git工作环境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim
向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git
将文件提交到远程Git服务器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository
http://www.linuxprobe.com/chapter-21.html#214_Git这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下
6. linux怎么搭建git服务器
GitHub就是一个免费托管开源代码的远程仓库。但是对于某些视源代码如生命的商业公司来说,既不想公开源代码,又舍不得给GitHub交保护费,那就只能自己搭建一台Git服务器作为私有仓库使用。
搭建Git服务器需要准备一台运行Linux的机器,强烈推荐用Ubuntu或Debian,这样,通过几条简单的apt命令就可以完成安装。
假设你已经有sudo权限的用户账号,下面,正式开始安装。
第一步,安装git:
$ sudo apt-get install git
第二步,创建一个git用户,用来运行git服务:
$ sudo adser git
第三步,创建证书登录:
收集所有需要登录的用户的公钥,就是他们自己的id_rsa.pub文件,把所有公钥导入到/home/git/.ssh/authorized_keys文件里,一行一个。
第四步,初始化Git仓库:
先选定一个目录作为Git仓库,假定是/srv/sample.git,在/srv目录下输入命令:
$ sudo git init --bare sample.git
Git就会创建一个裸仓库,裸仓库没有工作区,因为服务器上的Git仓库纯粹是为了共享,所以不让用户直接登录到服务器上去改工作区,并且服务器上的Git仓库通常都以.git结尾。然后,把owner改为git:
$ sudo chown -R git:git sample.git
第五步,禁用shell登录:
出于安全考虑,第二步创建的git用户不允许登录shell,这可以通过编辑/etc/passwd文件完成。找到类似下面的一行:
git:x:1001:1001:,,,:/home/git:/bin/bash
改为:
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
这样,git用户可以正常通过ssh使用git,但无法登录shell,因为我们为git用户指定的git-shell每次一登录就自动退出。
第六步,克隆远程仓库:
现在,可以通过git clone命令克隆远程仓库了,在各自的电脑上运行:
$ git clone git@server:/srv/sample.git
Cloning into 'sample'...
warning: You appear to have cloned an empty repository.
剩下的推送就简单了。
7. 如何搭建linux git服务器
首先我们分别在Git服务器和客户机中安装Git服务程序(刚刚实验安装过就不用安装了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do
然后创建Git版本仓库,一般规范的方式要以.git为后缀:
[root@linuxprobe ~]# mkdir linuxprobe.git
修改Git版本仓库的所有者与所有组:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/
初始化Git版本仓库:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/
其实此时你的Git服务器就已经部署好了,但用户还不能向你推送数据,也不能克隆你的Git版本仓库,因为我们要在服务器上开放至少一种支持Git的协议,比如HTTP/HTTPS/SSH等,现在用的最多的就是HTTPS和SSH,我们切换至Git客户机来生成SSH密钥:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
将客户机的公钥传递给Git服务器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.
此时就已经可以从Git服务器中克隆版本仓库了(此时目录内没有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#
初始化下Git工作环境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim
向Git版本仓库中提交一个新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean
但是这次的操作还是只将文件提交到了本地的Git版本仓库,并没有推送到远程Git服务器,所以我们来定义下远程的Git服务器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git
将文件提交到远程Git服务器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
为了验证真的是推送到了远程的Git服务,你可以换个目录再克隆一份版本仓库(虽然在工作中毫无意义):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository
这篇是详细介绍Git的,中间有一部分是怎么去搭建,你可以看下
8. 如何在 Linux 上安装 git 服务
Git 最初是一个在Linux下开发的非常流行的开源的版本控制系前运首统(VCS)。与其他的VCS工具(如CVS或者SVN)不同,Git在某种意义上考虑的是“分布式”,你本地的Git工作目录就可以作为一个完整的版本控制库并具有版本跟踪能力。在这种模式中,每一个协作者都可以提交到本地仓库,并且如果需要的话可以有选择的推送到一个集中的版本仓库。这种可扩展性和冗余的修订控制系统慧数是任何类型的大型协作任务中都是必须的。
一、通过包管理器安装 Git
Git 是所有主要的Linux发行版本都附带的功能。因此,安装Git的最简单的方法是使用您的Linux发行版的包管理器。
Debian, Ubuntu, or Linux Mint
$ sudo apt-get install git
Fedora, CentOS or RHEL
$ sudo yum install git
Arch Linux
$ sudo pacman -S git
OpenSUSE
$ sudo zypper install git
Gentoo
$ emerge --ask --verbose dev-vcs/git
二、从源代码安装Git
如果出于某种原因你想从源代码安装Git,你可以遵循下面的说明。
安装依赖
构建之前,首先安装Git依赖。
Debian,Ubuntu or Linux
$ sudo apt-get install libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev asciidoc xmlto docbook2x
Fedora, CentOS or RHEL
sudo yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel asciidoc xmlto docbook2x
从源代码编译Git
从 https://github.com/git/git/releases 下载最新版本的 Git,然后在 /usr 目录下构建悄裤和安装 Git。
注意,如果你想安装在一个其他的目录(如 /opt ),可以替换配置命令行中的 “--prefix=/usr ”。
$ cd git-x.x.x
$ make configure
$ ./configure --prefix=/usr
$ make all doc info
$ sudo make install install-doc install-html install-info
9. 在Linux下搭建Git服务器
众所周知,版本系统在开发环境中是必不可少的,但是我们可以把代码免费的托管到GitHub上,如果我们不原意公开项目的源代码,公司又不想付费使用,那么我们可以自己搭建一台Git服务器,可以用Gitosis来管理公钥,还是比较方便的。
搭建环境:
服务器 CentOS6.6 + git(version 1.8.3.1)
客户端 Windows10 + git(version 2.11.1.windows.1)
1. 安装Git相关软件
Linux是服务器端系统,Windows作为客户端系统,分别安装Git
安装客户端:
下载 Git for Windows,地址:https://git-for-windows.github.io/
安装完之后,可以使用Git Bash作为命令行客户端。
安装Gitosis
出现下面的信息表示安装成功了
2. 服务器端创建git用户来管理Git服务
3. 配置公钥
在Windows上配置管理者,git服务器需要一些管理者,通过上传开发者机器的公钥到服务器,添加成为git服务器的管理者,打开git命令行
4. 配置gitosis
使用git用户并初始化gitosis
在Windows上机器上clone gitosis-admin到管理者主机
gitosis.conf: git服务器配置文件
keydir: 存放客户端公钥
配置 gitosis.conf 文件
在Windows管理者机器上创建本地test仓库,并上传到git服务端
提交到远程服务器
服务端会自动创建test仓库
5.添加其他git用户开发者
由于公司开发团队人数不断增多,手动添加开发者私钥到/home/git/.ssh/authorized_keys比较麻烦,通过上面的Windows机器的管理者统一收集其他开发者的私钥id_rsa.pub文件,然后传到服务器上,配置好后,用户即获得项目权限,可以从远程仓库拉取和推送项目,达到共同开发项目。
推送完成后,新加进来的开发者就可以进行项目的开发了,后续增加人员可以这样添加进来,开发者直接把仓库clone下来就可以了。
10. linux如何搭建git
1、环境准备
服务器:CentOS 7.3 + git (1.8.3.1)
客户端:win10 + git (2.17.0.windows.1)
2、服务器安装git
yum install -y git
3、创建git用户,管理 git服务
[root@localhost home]# useradd git
[root@localhost home]# passwd git
4、服务器创建git 仓库
设置/home/git/repository-git 为git 服务器仓库,然后把 git 仓库的 owner 修改为 git 用户。
复制代码
[root@localhost git]# mkdir repository-git
[root@localhost git]# git init --bare repository-git/
Initialized empty Git repository in /home/git/repository-gt/
[root@localhost git]# chown -R git:git repository-git/
5、客户端安装git
下载 Git for Windows,地址:https://git-for-windows.github.io/
安装完之后,可以使用 Git Bash 作为命令行客户端。
5.1、选择一个目录 F:\project\sell 作为本地仓库,右键进入Git Bash 命令行模式
初始化本地仓库:git init
5.2、尝试克隆一个服务器的空仓库到本地仓库
git clone [email protected]:/home/git/repository-gt
第一次连接到目标 Git 服务器时会得到一个提示:
The authenticity of host '192.168.116.129(192.168.116.129)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/.
Are you sure you want to continue connecting (yes/no)?
选择 yes:
Warning: Permanently added '192.168.116.129' (RSA) to the list of known hosts.
此时 C:\Users\用户名\.ssh 下会多出一个文件 known_hosts,以后在这台电脑上再次连接目标 Git 服务器时不会再提示上面的语句。