1.环境配置说明

服务器 CentOS 7 + git(git version 1.8.3.1)
客户端 Windows10 + SourceTree

2.安装 Git

服务器端安装:

sudo yum -y install git

查看安装版本

#git --version
git version 1.8.3.1

客户端安装

下载 SourceTree for Window 下载地址:https://www.sourcetreeapp.com

3.git 服务器端创建 git 用户,用来管理 Git 连接使用服务,并为 git 用户设置密码,并且注册此用户无许登录SSH权限

[root@localhost home]#id git
id: git: no such user
[root@localhost home]#groupadd -g 108 -r git && useradd -s /sbin/nologin -u 108 -r -g git git
[root@localhost home]#passwd git

4.在服务器端创建 Git 仓库

[root@localhost home]#mkdir -p /opt/data/test.git
[root@localhost home]#git init --bare /opt/data/test.git
Initialized empty Git repository in /opt/data/test.git/
[root@localhost home]#chown -R git:git /opt/data/test.git

5.使用SourceTree 客户端打开终端 创建SSH公钥与私钥证书

1.创建证书,请在注明邮箱地址填写自己使用使用邮箱,因后面clone 会有认证

$ssh-keygen -t rsa -C "请输入邮箱地址"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Steven/.ssh/id_rsa):直接回车
Enter passphrase (empty for no passphrase):可输入密钥密码
Enter same passphrase again:确定密钥密码
Your identification has been saved in /c/Users/Steven/.ssh/id_rsa. 密钥所存放的位置
Your public key has been saved in /c/Users/Steven/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ryzmTky3Ar0l+gHX8m53VPJ0iwRuez1YgDlzomaaPtM
完整密钥这里会有你的邮箱地址
The key's randomart image is:
+---[RSA 2048]----+
| o |
| B o |
| o * . |
| . . + o..o..|
| o * S . o==..|
| B X o ..+.+ |
| . B + ... .|
| ooO.E. . |
| ++o*. . |
+----[SHA256]-----+

2.在服务器上配置SSH 认证支持密钥

进入vim  /etc/ssh 目录,编辑 sshd_config,打开以下三个配置的注释:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys

保存之后并重启 sshd 服务:

[root@localhost home]#systemctl restart sshd

因 AuthorizedKeysFile sshd_config 配置公钥的存放路径是 .ssh/authorized_keys,但实际上是 $Home/.ssh/authorized_keys,由于管理使用Git 服务的用户是 git,所以实际存放公钥的路径是 /home/git/.ssh/authorized_keys,同时把上一步所配置得到的id_rsa.pub 上传到服务器端

[root@localhost git]# pwd
/home/git
[root@localhost git]# mkdir .ssh
[root@localhost git]# ls -a
. .. .bash_logout .bash_profile .bashrc .gnome2 .mozilla .ssh id_rsa.pub

3.将客户端公钥导入服务器端 /home/git/.ssh/authorized_keys 文件

[root@localhost git]#cat id_rsa.pub >> /home/git/.ssh/authorized_keys

重要:

修改 .ssh 目录的权限为 700

修改 .ssh/authorized_keys 文件的权限为 777

[root@localhost git]# chmod 700 .ssh
[root@localhost git]# cd .ssh
[root@localhost .ssh]# chmod 777 authorized_keys

 

.客户端 SourceTree clone 远程仓库

重点注意:如果SSH 修改默认端口,配置方式跟默认并不一样

正常未修改SSH 端口:

git clone git@192.168.10.10:/opt/data/test.git

修改SSH端口配置方式

ssh://git@192.168.10.10:32569/opt/data/test.git

以上配置完成可正常使用

参考:在CentOS下搭建自己的Git服务器

Linux 环境 搭建Git 服务器,并且修改SSH端口使用的更多相关文章

  1. Windows/Linux 环境搭建Git服务器 + vs2012集成git

    1. 下载.安装Git 我的系统是Windows 7,需要安装Git for Windows. 下载地址: http://code.google.com/p/msysgit/downloads/lis ...

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

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

  3. 【转】Linux环境搭建FTP服务器与Python实现FTP客户端的交互介绍

    Linux环境搭建FTP服务器与Python实现FTP客户端的交互介绍 FTP 是File Transfer Protocol(文件传输协议)的英文简称,它基于传输层协议TCP建立,用于Interne ...

  4. 在linux中搭建git服务器

    个人觉得, 以下搭建git服务器的过程就像是在linux增加了一个用户, 而这个用户的登录shell是 git-shell, 太刨根问底的东西我也说不清楚, 还是看下面的过程吧. 过程参考了网上的文章 ...

  5. Linux Ubuntu搭建git服务器

    1. 安装 openssh-server ,用于创建SSH服务. sudo apt-get install openssl-server 使用命令ps -e|grep ssh,查看ssh服务是否启动. ...

  6. 在 Linux 下搭建 Git 服务器

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

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

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

  8. linux 简单搭建git服务器

    如果使用git的人数较少,可以使用下面的步骤快速部署一个git服务器环境. 1. 生成 SSH 公钥 每个需要使用git服务器的工程师,自己需要生成一个ssh公钥进入自己的~/.ssh目录,看有没有用 ...

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

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

随机推荐

  1. Java Web实现用户登录界面

    一.学习Java Web需要的技术: Java语言基础:算法基础.常用数据结构.编程规范. 掌握常见的数据结构和实用算法:培养良好的编程习惯. Java面向对象:封装.继承.多态等,面向对象程序设计, ...

  2. iOS 部分API理解

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  3. 吴裕雄--天生自然C语言开发:存储类

    { int mount; auto int month; } { register int miles; } #include <stdio.h> /* 函数声明 */ void func ...

  4. Spring Cloud服务消费者(rest+ribbon)

    在上一篇文章,讲了服务的注册和发现.在微服务架构中,业务都会被拆分成一个独立的服务,服务与服务的通讯是基于http restful的.Spring cloud有两种服务调用方式,一种是ribbon+r ...

  5. 腾讯云 Serverless 首发 1ms 计费粒度,立省 70% 费用

    云函数 SCF 采用按需付费的方式,并首次发布 1ms 计费粒度,真正实现按使用多少计算能力来计费. 云函数(Serverless Cloud Function,SCF)是腾讯云为企业和开发者们提供的 ...

  6. WebElement--定位经验

    通常,我们这页面中定位一个元素,如果HTML中明明有却定位不到,我们一定会从这两个方面考虑. 第一:是不是页面中有多个iframe/frame结构,很多情况下我们需要通过切换iframe/frame结 ...

  7. Spring @Column的注解详解

    就像@Table注解用来标识实体类与数据表的对应关系类似,@Column注解来标识实体类中属性与数据表中字段的对应关系. 该注解的定义如下: @Target({METHOD, FIELD}) @Ret ...

  8. [LC] 513. Find Bottom Left Tree Value

    Given a binary tree, find the leftmost value in the last row of the tree. Example 1: Input: 2 / \ 1 ...

  9. 62)PHP,提示跳转

    由于就是一个普通的页面展示,提示的样式,可以轻松定制! 语法: Header()后的代码会执行,因此在处理好跳转相关操作后,脚本也应该被DIE掉! 案例中实现跳转 封装一个可以完成跳转的方法,需要时, ...

  10. Fourier级数

    目录 Fourier级数 函数的Fourier级数的展开 Fourier级数习题: Fourier级数 函数的Fourier级数的展开 Euler--Fourier公式 我们探讨这样一个问题: 假设\ ...