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 

 

6.客户端 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服务器

转载于:https://www.cnblogs.com/itusye/p/6533324.html

Linux 环境 搭建Git 服务器,并且修改SSH端口使用相关推荐

  1. linux git服务器搭建端口号是多少,Linux 环境 搭建Git 服务器,并且修改SSH端口使用...

    1.环境配置说明 服务器 CentOS 7 + git(git version 1.8.3.1) 客户端 Windows10 + SourceTree 2.安装 Git 服务器端安装: sudo yu ...

  2. git ssh配置文件 服务器_Linux 环境 搭建Git 服务器,并且修改SSH端口使用

    1.环境配置说明 服务器 CentOS 7 + git(git version 1.8.3.1) 客户端 Windows10 + SourceTree 2.安装 Git 服务器端安装: sudo yu ...

  3. kali系统搭建本地服务器,kali linux 下搭建git服务器

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

  4. Linux Ubuntu搭建git服务器

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

  5. 在 Linux 下搭建 Git 服务器

    来源:https://www.cnblogs.com/dee0912/p/5815267.html 环境: 服务器 CentOS6.6 + git(version 1.7.1)客户端 Windows1 ...

  6. linux下搭建git服务器

    安装 Git Linux 做为服务器端系统,Windows 作为客户端系统,分别安装 Git 服务器端: #yum install -y git 安装完后,查看 Git 版本 [root@localh ...

  7. 一分钟在Linux 环境 搭建 SFTP服务器

    文章目录 一.实战 1. 创建sftp组: 2. 创建一个用户sftpuser: 3. 设置sftpuser用户的密码,会要求你输入两次密码确认: 4. 创建一个sftp的上传目录: 5. 修改用户s ...

  8. linux搭建ldap服务器详细步骤,linux环境搭建ldap服务器

    首先保证linux正常联网 yum install openldap-servers -y 拷贝配置文件 cd /usr/share/openldap-servers/ cp slapd.conf.o ...

  9. linux环境搭建golang服务器,Linux下golang环境搭建-Go语言中文社区

    1.首先从使用wget https://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz命令下载安装包,可以根据自己的需要选择版本. 2. ...

最新文章

  1. mysql--多实例启动方法
  2. 如何安装系统认证签名过的APK
  3. 二叉树的递归和非递归遍历
  4. innodb_force_recovery的值意思
  5. MSHA x Chaos 容灾高可用实践
  6. 你所忽略的Linux系统安全及应用(最全面)
  7. SAP: 如何取物料主数据的特性值
  8. MyBatis初级入门及常见问题
  9. MySQL高级 —— 查询性能优化
  10. Qt总结之一:遍历文件夹和文件目录,并过滤和获取文件信息、后缀名、前缀名(一)
  11. linux离线语音识别安装运行总结
  12. iphone投屏老是显示无法连接服务器,iphone怎么投屏到电视 升级iOS11后为什么投屏会失败...
  13. neo4j图数据库导入scv文件
  14. CNZZ埋点及点击量统计方法
  15. PHP微信支付 “商家转账到零钱”一文概述
  16. Temporal Anti-Aliasing(时域抗锯齿TAA)
  17. java获取浏览器url_java 打开浏览器 url
  18. 【OpenGL学习笔记①】——openGL flew flgw flut 环境配置 + 绘制出Hello World
  19. Linux input 子系统详解
  20. linux中文麻酱字_在家自制芝麻酱、芝麻香油,味道纯正无添加,原来做法这么简单...

热门文章

  1. 转: Android ListView 滑动背景为黑色的解决办法
  2. 开源项目贡献者_嘿新手开源贡献者:请写博客。
  3. 9 单元测试中不得不知的概念
  4. java 查询 代码_java使用es查询的示例代码
  5. Python培训常识:Python面试中常被问到的几种设计模式要知道
  6. 软测培训机构哪个比较好
  7. 微软推出Windows XP/Server 2003紧急安全补丁:修复远程桌面CVE-2019-0708漏洞
  8. 记录智能指针使用shared_ptr使用错误
  9. Template mode HTML5 has not been configured
  10. C++模式学习------策略模式