Linux Ubuntu搭建git服务器
1. 安装 openssh-server ,用于创建SSH服务。
sudo apt-get install openssl-server
使用命令ps -e|grep ssh,查看ssh服务是否启动。
如果正常启动,则会显示类似信息:1966 ? 00:00:00 ssh-agent
2. 创建用户名为git的用户,用来管理和运行git服务。
sudo user del -r git // 删除已经存在的叫git的用户; sudo adducer git // 添加用户名叫git的用户;
进入git用户目录下,创建目录.ssh,然后在.ssh目录下创建名为authorized_keys的文件;
cd /home/git sudo mkdir .ssh cd .ssh touch authorized_keys
将客户端的公钥(生成方法见后文)拷贝到authorized_keys文件中;
cat path/id_rsa.pub >> /home/git/.ssh/authorized_keys
安装 git-core
sudo apt-get install git-core
3. 初始化服务端仓库
git —bare init /home/git/test1.git
注:该命令会生成一个空仓库,此时test1.git对应的地址则为git@hostIp:/home/git/test1.git
或者:
mkdir test1.git cd test1.git git —bare init
4. 客户端运行ssh-keygen -t rsa生成密钥;
生成密钥后,在.ssh目录下,会有两个文件id_rsa和id_rsa.pub文件,id_rsa.pub为公钥,通过命令scp /home/git/.ssh/id_rsa.pub gitServer:/home/git将client上生成的公钥拷贝到gitServer上;
服务端把公钥添加到authorized_keys文件中后,客户端就能通过路径访问到git仓库了;
生成密钥时,会要求你确认保存公钥的位置(默认为~/.ssh/id_rsa),然后会让重复一个密码两次,如果不想在使用公钥的时候输入密码,则留空;
假定hostIp为192.168.1.100
git clone git@192.168.1.100:/home/git/test1.git
5. 常用git命令
>1. git clone
语法:git clone 版本库网址 本地库名称(可省略)
>2. git remote
此命令用于管理远程主机名,在没有参数的情况下可以列出所有主机名;
git remoteorigin
显示origin是在使用clone命令,克隆远程版本库时git自动为远程主机命令;
通过git remote -v 查看版本库的地址;
>3. git fetch
语法:git fetch origin(git fetch origin master)
默认情况下,git fetch origin将会更新远程主机origin上所有分支,如果只想更新某个分支则在主机名后加分支名
>4. git push
语法:git push 远程主机名 本地分支名:远程分支名
如果省略远程分支名,则表示将本地分支推送与存在最终关系的远程分支,如果远程分支不存在,则会被创建;
git push origin master,表示将本地master分支推送到origin主机的master分支;
如果省略本地分支名,则表示要删除远程主机中的分支,如git push origin : master,则表示删除origin主机中的master分支;
>5. git pull
语法:git pull 远程主机 远程分支:本地分支 如:git pull origin master:master,表示将远程主机origin中的master分支更新到本地分支master;
6. 每次添加一个新项目都需要通过shell登入主机并创建一个纯仓库,我们不妨以gitServer作为git用户和仓库所在的主机名,如果你在网络内部运行该主机,并且在DNS中设定gitServer指向该主机,则以下这些命令都是可用的:
cd myproject git init git add . git commit -m “initial commit” git remote add origin git@gitServer:test1.git git push origin master
创建一个版本库仓库
这样,其它人的克隆和推送也一样
git clone git@gitServer:/test1.git vim README git commit -am ‘fix for the README file’ git push origin master
7. 作为一个额外的防护措施,可以用git自带的git-shell工具来把git用户的活动限制在仅与git相关。把它设为git用户登入的shell,那么该用户就不能拥有主机正常的shell访问权,为了实现这一点,需要指明用户的登入shell为git-shell,而不是 bash 或者 csh,可以通过编辑/etc/passwd文件
sudo vim /etc/passwd
在文件末尾,找到类似此行
git:x:1000:1000::/home/git:/bin/sh
将bin/sh改为/usr/bin/git-shell
git:x:1000:1000::/home/git:/usr/bin/git-shell
现在git用户只能用ssh连接来推送和获取git仓库,而不能直接使用主机shell。
8. Q&A
(1)
Q:
xiongmc@xiongmc-desktop:~/myproject2$ git push origin master
Agent admitted failure to sign using the key.
git@localhost's password:
error: src refspec master does not match any.
error: failed to push some refs to 'git@localhost:/opt/git/project.git/'
A:如果初始的代码仓库为空,git push origin master提交代码的时候会出现以上异常
http://www.linuxidc.com/Linux/2013-03/81022.htm
(2)
Q:
xiongmc@xiongmc-desktop:~/myproject2$ git push origin master
Agent admitted failure to sign using the key.
git@localhost's password:
Permission denied, please try again.
git@localhost's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
error: insufficient permission for adding an object to repository database ./objects
fatal: failed to write object
error: unpack failed: unpack-objects abnormal exit
To git@localhost:/opt/git/project.git/
! [remote rejected] master -> master (n/a (unpacker error))
error: failed to push some refs to 'git@localhost:/opt/git/project.git/'
A: 服务器无权限。
http://blog.sina.com.cn/s/blog_53e449530101349s.html
http://stackoverflow.com/questions/1918524/error-pushing-to-github-insufficient-permission-for-adding-an-object-to-reposi
sudo chown -R git:gitgroup path/to/repo.git/ // or sudo chown -R git:git path/to/repo.git/
(3)
http://www.linuxidc.com/Linux/2013-03/81022.htm
Q:
xiongmc@xiongmc-desktop:~/myproject2$ git push origin master
Agent admitted failure to sign using the key.
git@localhost's password:
Counting objects: 3, done.
Writing objects: 100% (3/3), 213 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To git@localhost:/opt/git/project.git/
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'git@localhost:/opt/git/project.git/'
A:
$cd .git
$vim config
该配置文件的原始内容为:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
在该配置文件中加入以下内容:
[receive]
denyCurrentBranch = ignore
(4)
Linux服务器:Ubuntu配置git服务 - 逸云沙鸥
http://www.xue5.com/Server/Linux/667461.html
(5)为了集成到SCM,我们在Linxu上安装GIT
http://www.examw.com/linux/all/182529/index-2.html
在LINUX上创建GIT服务器
http://lionest.iteye.com/blog/1447310
http://blog.csdn.net/andy_android/article/details/6996134
Receiving objects: 26% (5668/21560), 8.06 MiB | 183 KiB/s 21560)
(6)
Q:
xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master ssh: connect to host xiongmc-desktop port 22: Connection refused
fatal: The remote end hung up unexpectedly
xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master
ssh: connect to host xiongmc-desktop port 22: Connection refused
fatal: The remote end hung up unexpectedly
A:
http://blog.csdn.net/zlm_250/article/details/7979221
sudo apt-get install openssh-server
sudo net start sshd
sudo ufw disable
ssh localhost
(7)
Q:
ubuntu系统下“关于'xx'用户不在 sudoers文件中,此事将被报告。”的解决方法
A:
http://blog.sina.com.cn/s/blog_bede36550101b0av.html
git ALL=(ALL:ALL) ALL
(8)
Q:
xiongmc@xiongmc-desktop:~/myproject.git$ git push origin master
git@xiongmc-desktop's password:
fatal: '/opt/git/project.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly
A:
http://www.dotkam.com/2010/08/22/gitolite-does-not-appear-to-be-a-git-repository/
转载于:https://www.cnblogs.com/a284628487/p/3729246.html
Linux Ubuntu搭建git服务器相关推荐
- linux git服务器搭建端口号是多少,Linux 环境 搭建Git 服务器,并且修改SSH端口使用...
1.环境配置说明 服务器 CentOS 7 + git(git version 1.8.3.1) 客户端 Windows10 + SourceTree 2.安装 Git 服务器端安装: sudo yu ...
- kali系统搭建本地服务器,kali linux 下搭建git服务器
参考:http://www.cnblogs.com/dee0912/p/5815267.html https://www.liaoxuefeng.com/wiki/001373951630592960 ...
- linux ubuntu 安装git服务器,[linux] Ubuntu20.04上安装搭建私有Git服务器Gitea
[linux] Ubuntu20.04上安装搭建私有Git服务器Gitea [linux] Ubuntu20.04上安装搭建私有Git服务器Gitea Gitea 是相比于gitlab更加轻量化,而且 ...
- 转载-ubuntu搭建Git 服务器
本文转载自:http://blog.chinaunix.net/uid-15007890-id-3217101.html 硬件需求:一台linux Ubuntu电脑(虚拟机),在公司局域网内有独立IP ...
- Linux 环境 搭建Git 服务器,并且修改SSH端口使用
1.环境配置说明 服务器 CentOS 7 + git(git version 1.8.3.1) 客户端 Windows10 + SourceTree 2.安装 Git 服务器端安装: sudo yu ...
- linux下搭建git服务器
安装 Git Linux 做为服务器端系统,Windows 作为客户端系统,分别安装 Git 服务器端: #yum install -y git 安装完后,查看 Git 版本 [root@localh ...
- linux svn 指定端口号,linux(Ubuntu)搭建Subversion服务器+修改svn端口号
一.搭建 Subversion 服务器 1.首先需要安装 subversion 这个软件: sudo apt-get install subversion 注:使用apt-get安装软件,ubuntu ...
- 在 Linux 下搭建 Git 服务器
来源:https://www.cnblogs.com/dee0912/p/5815267.html 环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows1 ...
- Ubuntu搭建git服务器,外网可访问
gitlab服务器和创建git仓库 https://www.linuxidc.com/Linux/2018-01/150319.htm 访问git仓库 域名申请 比如https://www.huahu ...
最新文章
- Unity创建2D动作RPG游戏 Create Action 2D RPG Game in Unity
- U盘中毒,无法删除System Volume Information文件夹
- smarty_modifier_truncate,无或者有md_substr的情况下都能正确截取字符串的php函数,可用于smarty。...
- 【转】CEC文件详解
- [caffe] 数据制作和训练
- 汇编语言——键盘输入字符
- 不同Unix环境下date计算日期的用法
- python 两种多线程比较
- SQL Server通过动态视图里查找阻塞超过30秒的会话
- sml完整形式_教资会的完整形式是什么?
- golang mysql curd_Go 语言操作 MySQL 之 CURD 操作
- ECS服务器下挂载数据盘
- jetson nano 相关设置(开机自动登录、取消休眠和屏保、开机自启动程序)
- 1929. 数组串联
- UIScrollView与分页的联合使用
- CATIA二次开发—漫谈开发环境
- Python版解决中文字符串错误
- c语言中ifelse语句的例子,ifelse语句例子
- [slove]Unable to find required classes (javax.activation.DataHandler and javax.m
- java matlab 遗传算法_简单遗传算法MATLAB实现