我这里用的是redhat7.4, 直接开始吧.

环境

服务端: Redhat7.4 + git(version 1.8.3.1) IP:192.168.137.168
客户端: win7 + git (version 2.19.1)

Git

server:

[root@localhost gittest.git]# git --version
git version 1.8.3.1

我这里是有的, 没有的话

yum install git -y

client:

官网地址: https://git-for-windows.github.io/

服务器操作

  • 新建git用户与赋予密码
useradd git
passwd git

注:这里的密码我用1234

  • 为服务器创建一个git用的文件夹(git仓库)
mkdir /usr/local/gittest.git

注:这个目录可以随便建(项目在哪就放哪), 只要后面授权给git用户管理就行

  • 初始化
git init --bare /usr/local/gittest.git
  • 授权
chown -R git:git /usr/local/gittest.git

注:这个就很简单了,在/usr/local/gittest.git下会看到生成了目录

客户端操作

注:这一波用的不是powershell或者cmd, 确定客户端的git已安装.

  • 简介

  • 新建目录
hp@hp-PC MINGW64 /d/wamp64
$ mkdir gittest_gitbash hp@hp-PC MINGW64 /d/wamp64
$ ls
gittest/ gittest_gitbash/ www/
c
hp@hp-PC MINGW64 /d/wamp64
$ cd gittest_gitbash/
hp@hp-PC MINGW64 /d/wamp64/gittest_gitbash
$ pwd
/d/wamp64/gittest_gitbash
  • clone项目
git clone git@192.168.137.168:/usr/local/gittest.git

注:这个就很容易理解了, 将服务器上面的文件夹下的东西拉取到本地(就是这个目录下d:\wamp64\gittest_gitbash)

  • 自动弹出提示
The authenticity of host '192.168.137.168 (192.168.137.168)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/SCA059EqoUOzbFoZdfmMh3B259nigfmvdadqQ.
Are you sure you want to continue connecting (yes/no)? yes

成功!

  • 发现
 此时会在本地C:\Users\用户名\.ssh 下生成文件 known_hosts
  • 创建公钥私钥
ssh-keygen -t rsa -C "邮箱"

注:此时C:\Users\用户名\.ssh 下会多出两个文件 id_rsa 和 id_rsa.pub

  • 服务器Git打开rsa认证
[root@localhost gittest.git]# cd /etc/ssh/
[root@localhost ssh]# ls
moduli sshd_config ssh_host_ecdsa_key.pub ssh_host_ed25519_key.pub ssh_host_rsa_key.pub
ssh_config ssh_host_ecdsa_key ssh_host_ed25519_key ssh_host_rsa_key
[root@localhost ssh]# vim sshd_config
  • 打开三个注释
RSAAuthentication yes
PubkeyAuthentication yes AuthorizedKeysFile .ssh/authorized_keys

  • 重启sshd
systemctl stop sshd.service
systemctl start sshd.service
  • 在git用户目录新建.ssh目录
mkdir /home/git/.ssh
  • 授权
chown -R git:git /home/git

  • 将客户端公钥上传到服务器端git用户目录.ssh
cd C:\Users\用户
ssh git@192.168.137.168 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

注:这里要切换到.ssh的上一级目录, 因为要将authorized_keys文件当前内容上传到服务器中

  • 再看一下服务器上面的目录

  • 客户端再次clone远程仓库
git clone git@192.168.137.168:/usr/local/gittest.git

结尾

  • 禁止git用户ssh登录
vim /etc/passwd

git:x:1004:1005::/home/git:/bin/bash
改为
git:x:1004:1005::/home/git:/bin/git-shell

  

Git服务器搭建完毕!

后续

  • 删除远程分支点
git remote remove origin

  • 新建远程分支点
origin 为远程仓库别名  后面http 为远程仓库地址
git remote add origin git@192.168.137.168:/home/git/data/git/learngit.git

  • 本地库提交到远程分支(上传)
git push <远程主机名> <本地分支名>:<远程分支名>
git push learngit master:origin

  • 本地分支拉取远程分支(下载)

linux下部署git服务器的更多相关文章

  1. 【转】在Linux下搭建Git服务器

    在 Linux 下搭建 Git 服务器 环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.windows. ...

  2. Linux下部署FTP服务器

    Linux下部署FTP服务器 下载安装包 在这里介绍的是离线部署FTP,首先下载对应的rpm包,下载链接为: 下载vsftpd服务 下载FTP客户端 安装ftp服务器 关闭防火墙 service ip ...

  3. Linux下搭建Git服务器

    1.安装Git 见 Jenkins持续集成环境部署 第四节 2.创建Git用户和用户组 groupadd git useradd git -g git 3.创建证书切换到git用户创建证书 su gi ...

  4. 在 Linux 下搭建 Git 服务器

    环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows10 + git(version 2.8.4.windows.1) ① 安装 Git Linux 做为 ...

  5. 在Linux下搭建Git服务器的方法是什么样?

    第一步 安装git:可以通过命令的方式快速安装,不同的linux的安装方法可能不一样,我的是采用的yum方法.ubuntu可以用apt-get命令.sudo yum install git 第二步 添 ...

  6. 在 Linux 下搭建 Git 服务器(yum安装)

    服务端(linux): 1. 安装git [root@localhost ~]# yum -y install git 2. 增加一个git账户 为了管理的方便,在linux下面增添一个 " ...

  7. 在Linux下搭建Git服务器步骤

    环境: 服务器 CentOS6.6 + git(version 1.7.1) 客户端 Windows10 + git(version 2.8.4.windows.1)  ① 安装 Git Linux ...

  8. Linux 下搭建Git 服务器详细步骤

    参考: https://www.cnblogs.com/dee0912/p/5815267.html#_label0 https://blog.csdn.net/carfge/article/deta ...

  9. kali linux 下搭建git服务器

    参考:http://www.cnblogs.com/dee0912/p/5815267.html https://www.liaoxuefeng.com/wiki/001373951630592960 ...

随机推荐

  1. 使用Github进行代码管理

    准备: Github地址:https://github.com 注册Github帐号 一.新建仓库 进入如下界面: 到这里仓库就创建完成了. 二.安装Github-window-desktop 安装g ...

  2. Selenium基本使用(十二)测试报告生成

    报告目录结构 Reporter根目录 | |-------------LOGS |                                                | |         ...

  3. 网络编程之Socket的TCP协议实现客户端与客户端之间的通信

    我认为当你学完某个知识点后,最好是做一个实实在在的小案例.这样才能更好对知识的运用与掌握 如果你看了我前两篇关于socket通信原理的入门文章.我相信对于做出我这个小案列是完全没有问题的!! 既然是小 ...

  4. 利用css伪类编写冒泡小三角

    HTML代码 <div class="lf otherLogin"> <span>其他方式注册</span> <div class=&qu ...

  5. LeetCode160.相交链表

    编写一个程序,找到两个单链表相交的起始节点. 例如,下面的两个链表: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 在节点 c1 开始相交. 注意: 如果两个 ...

  6. 14. Longest Common Prefix(暴力循环)

    Write a function to find the longest common prefix string amongst an array of strings. If there is n ...

  7. map 的用法

    #include<iostream> #include<map> #include<string> #define s second #define f first ...

  8. IoC, DI,Spring.net

    IoC : Inversion of Control , 控制反转,就是创建对象(实例)的权利由开发人员自己控制New转到了由容器来控制.实现了解耦. DI: Dependency Injection ...

  9. numpy高级索引

    布尔值索引 name_arr = np.array(["bob","joe","will","bob","jo ...

  10. redis相关问题

    什么是Redis?Redis 是一个使用 C 语言写成的,开源的 key-value 数据库..和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表 ...