我这里用的是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. Makefile中变量定义中末尾不能有空格

    我在Makefile中添加了 ifndef EMASSDIR EMASSDIR=$(shell emassTop.py)endif 但是emassTop.py)后面不小心加入了空格,造成出现“Make ...

  2. Linux:系统文件目录

    目录结构 bin:命令类目录 命令 系统操作 清屏:clear.ctrl+L 进程: # $(ps -ef | grep hnlinux) //方法一 过滤出hnlinux用户进程 #kill -u ...

  3. import Tkinter error, no module named tkinter: "Python may not be configured for Tk”

    install required devel module in your linux: yum install tk-devel yum install tcl-devel then,reconfi ...

  4. cocos2d-x C++ 原始工程引擎运行机制解析

    新建一个工程,相信感兴趣的同学都想知道cocos引擎都是如何运行的 想知道是如何运行的,看懂四个文件即可 话不多说,上代码: 1.首先解释 AppDelegate.h #ifndef _APP_DEL ...

  5. Could not find result map java.lang.Integer] with root cause

    错误的代码 <select id="selectpGoodsInfoIdByGoodsId" parameterType="java.lang.Integer&qu ...

  6. JDK源码调试常见错误。

    1.删除不需要的代码,即swing相关的代码 2.执行命令时要将前提环境进入文件夹如下: 起初没有完全执行第一条,因为网上说可以根据需要选择相关的代码,于是就没有删除,以后第一次模仿网上的例子的时候要 ...

  7. HTML布局规范

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. Python全栈-day11-函数3

    装饰器 1.开放封闭原则 通常情况下,软件一旦上线就应该遵循开放封闭原则,即对修改封闭.对扩展开放 扩展开放需遵循两个原则: 1)不修改源代码 2)不修改原函数的调用方式 2.装饰器 器指的是工具,装 ...

  9. 2-1:math库与random库

    一.math库: math库是python语言中常用的一个函数库,它包含了一批数学函数,下面我们看一下这个函数库 由于math库中的函数与数学中的函数比较一致,相对比较简单,请同学们自行练习一下: 二 ...

  10. workerman程序调试

    现象1 启动后报错类似如下: php start.php start PHP Warning: stream_socket_server(): unable to connect to tcp://x ...