参考:

GitHub Help: Connecting to GitHub with SSH

廖雪峰的官方网站: 搭建Git服务器

菜鸟教程: Git 服务器搭建

1. 安装记录(可能有错。。。)

本地( Debian 8.8):

sudo apt-get install gitgit version # 确保正确安装

root@xkfx:~# git config --global user.name "little fish"
root@xkfx:~# git config --global user.email "little_fish@163.com"
# 初始设置,作为储存在本地的变量,会用在Git的提交日志中
root@xkfx:~# git config user.name
little fish
root@xkfx:~# git config user.email
little_fish@163.com

生成 ssh key (这个不是 git 命令!),

root@xkfx:~# ssh-keygen -t rsa -C "little_fish@163.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
53:f3:c5:06:28:61:3f:12:36:fc:54:c7:df:4c:9c:60 little_fish_pubic@gmail.com # 已改,仅作示范
The key's randomart image is:
+---[RSA 2048]----+
|     .*..+o..E...|
|     o.++  +o  .o|
|      .oo + +. + |
|       ..o =  . o|
|        S   .    |
|         .       |
|                 |
|                 |
|                 |
+-----------------+

总之本地持有私匙,远程持有对应公匙,这样双方才能安全通信。关于邮箱参数有啥用可以参考这个文档(是作为 ssh key 的一个标签,这在仓库放在 github 上的时候会有用 ~)密码是给私匙配的。

VPS(Centos 6 x86 bbr ):

[root@xkfx ~]# yum install git
[root@xkfx ~]# git version

把有权限访问的【终端的公匙】拷贝进去,一行一个,

root@xkfx:~# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGetaJDc9kTMrRlw+++ve+w4gamJH2LfNC9qJa/LbvXUFkO1atJCQxn2DlaNvQxrMvSSAHRNo2MmNnxRp9Vi8sg6KawgVKx6n60maMxvMugkzV+BOm8ds+C5M+JAdRzjBzfdgWIMgdqZfyfG1sHnTg6JGvzCxJ9DigNb+2cho20CXhCv5JKsn2fHzyc75BguT8gxZ7e9vtQNWywLNNse8mCFmc28kmxXo14eDuZPbDGnEU12BO+UFVqYbeFVNLVcS8x2GiJg/Iy5pDCPScPI0iyZGor7AkI0SjfhQuc4uMDVIDWC5gp8cqudxP little_fish_pubic@gmail.com

[root@xkfx ~]# sudo adduser git
[root@xkfx ~]# cd /home/git
[root@xkfx git]# mkdir .ssh
[root@xkfx git]# vim /home/git/.ssh/authorized_keys

[root@xkfx git]# sudo git init --bare sample.git
Initialized empty Git repository in /home/git/sample.git/

出于安全性考虑,

[root@xkfx git]# sudo chown -R git:git sample.git
[root@xkfx git]# vim /etc/passwd

2.基本操作尝试

root@xkfx:~# git clone git@your ip address:/home/git/sample.git
Cloning into 'sample'...
ssh: connect to host your ip address port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

---------------------------------------------------------------------------------------

root@xkfx:~# eval $(ssh-agent -s)
Agent pid 16083
root@xkfx:~# ssh-add ~/.ssh/id_rsa
Enter passphrase for /root/.ssh/id_rsa:
Bad passphrase, try again for /root/.ssh/id_rsa:
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)

root@xkfx:~# ssh -T git@your ip address
ssh: connect to host your ip address port 22: Connection refused

---------------------------------------------------------------------------------------

root@xkfx:~# ssh -T git@github.com
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Permission denied (publickey).
---------------------------------------------------------------------------------------

换菜鸟教程从头敲一遍 失败

换了个 VPS 按照菜鸟教程重敲了一遍 就成功了。

root@xkfx:~# groupadd git
root@xkfx:~# useradd git -g git
root@xkfx:~# cd /home/git/
root@xkfx:/home/git# mkdir .ssh
root@xkfx:/home/git# chmod 755 .ssh
root@xkfx:/home/git# touch .ssh/authorized_keys
root@xkfx:/home/git# chmod 644 .ssh/authorized_keys
root@xkfx:/home/git# cd /home
root@xkfx:/home#  mkdir gitrepo
root@xkfx:/home# chown git:git gitrepo/
root@xkfx:/home# cd gitrepo
root@xkfx:/home/gitrepo# git init --bare runoob.git
Initialized empty Git repository in /home/gitrepo/runoob.git/
root@xkfx:/home/gitrepo# chown -R git:git runoob.git # 必要的!否则会因为权限不够无法 push
root@xkfx:/home/gitrepo# vim /home/git/.ssh/authorized_keys

mdzz@LAPTOP-QGECNCGO MINGW64 /d/labs

$ git clone git@????????????:/home/gitrepo/runoob.git
Cloning into 'runoob'...
warning: You appear to have cloned an empty repository.

3. 应用

存放不愿公开的项目

作为网盘方便地保存重要文件

例如打算写个小项目:

在 VPS 上建立仓库,无论你在本地是否已经开始写(写了就 移花接木 :D)

VPS:

root@xkfx:/home/gitrepo# git init --bare mangast.git
root@xkfx:/home/gitrepo# chown -R git:git mangast.git

本地:

$ git clone git@????????????:/home/gitrepo/mangast.git

--------- 移 花 接 木 ------

$ git add sql/ src/ web/

$ git commit -m "basis."

$ git push origin master

转载于:https://www.cnblogs.com/xkxf/p/8510817.html

Linux笔记 #06# 在VPS上自建Git服务相关推荐

  1. Gogs这款开源项目助你秒建Git服务!

    一.简介 以前使用 Gitlab 搭建过 Git 服务的小伙伴都知道,这个 GitLab 方案占用内存比较大,没有个8G 内存,很难流畅运行,而且部署起来也不容易.所以今天的主角他来了,Gogs 是一 ...

  2. 【哈佛公开课】积极心理学笔记-06乐观主义(上)

    好久没听了,还是觉得应该尽快把课程听完,之后尽量一周最少听一节,希望自己可以尽量积极些. [06]乐观主义(上) 上一讲讲述了环境对人的影响是巨大的:实验表明,人们在特定的环境中会过于"入戏 ...

  3. 黑马Linux笔记05【Linux系统软件安装,MySQL、Tomcat、Nginx、RabbitMQ、Redis、ElasticSearch、Zookeeper】

    视频资源 视频地址:黑马-新版Linux快速入门到精通 资源下载:https://pan.baidu.com/s/1zExrsk09QVm3mpqaPTqe_g?pwd=6666,提取码:6666 课 ...

  4. [Linux]在Linux上部署Java开发环境笔记(一)-- 补充:Linux下如何手动设置IP及配置DNS服务

    在Linux上部署Java开发环境笔记(一) -- 补充:Linux下如何手动设置IP及配置DNS服务 2010/06/17 有的Linux系统会有网络设置的图形操作界面,比如"红旗Linu ...

  5. 【树莓派学习笔记】树莓派4B上运行uboot并从网络启动linux内核(上)

    [树莓派学习笔记]树莓派4B上运行uboot并从网络启动linux内核(上) 文章目录 [树莓派学习笔记]树莓派4B上运行uboot并从网络启动linux内核(上) 前言 1. 硬件需求与软件版本汇总 ...

  6. OS和Linux笔记

    OS和Linux笔记 操作系统 基本概念 进程管理 进程和线程 协程 同步互斥 死锁 CAS技术 IPC 线程间通信 内存管理 Linux 基础知识 守护进程 系统监测 编译调试 文件管理 零拷贝技术 ...

  7. 数据之道读书笔记-06面向“自助消费”的数据服务建设

    数据之道读书笔记-06面向"自助消费"的数据服务建设 数据底座建设的目标是更好地支撑数据消费,在完成数据的汇聚.整合.联接之后,还需要在供应侧确保用户更便捷.更安全地获取数据.一方 ...

  8. Linux笔记 [全文字数1.6W]

    Linux笔记 文章目录 Linux笔记 第一章 Linux基本介绍 1.1 Linux目录结构 1.1.1 具体的目录结构 1.1.2 总结 1.2 vi和vim编辑器 1.2.1 定义 1.2.2 ...

  9. linux中文麻酱字_【树】Linux笔记 1

    以下内容是参与[生信技能树-全球听第7期]的课程笔记,记录人:小瑛  ,有问题可在公众号后台留言 小白小白,请注意:笔记中出现的所有文件路径,仅作为参考,请勿模仿! 1. 登录服务器 1.1 Mac电 ...

最新文章

  1. DBUtils 笔记
  2. Nginx的upstream目前支持5种分配方式
  3. webgl 基础渲染demo_游戏引擎养成《二》 引入跨平台渲染库
  4. IDEA MAVEN Project 显示问题
  5. 切洋葱怎么才不流泪?
  6. 前端笔记-thymeleaf获取及回显input标签type=radio
  7. 进价移动加权核算体系
  8. opencv4nodejs安装
  9. MATLAB ttest和ttest2的区别
  10. 腾讯三面:Cookie的SameSite了解吧,那SameParty呢?
  11. 未能解决并且期待解决的第二个诡异事件----HashMap相关方法
  12. 朱松纯将回国加入清华,曾对李飞飞创建ImageNet有启示
  13. Spring 你让我伤透了个心啊!
  14. 全网热议的云原生技术到底什么?看完这25点你就知道了
  15. C#经常用到的编程词汇
  16. Blazor开发WEB程序
  17. Win10如何自定义右键菜单-修改注册表(图文)
  18. 前端系列 | 2015年双11手淘前端技术巡演 - 前言
  19. 你业余时间在做什么?
  20. centos6操作系统升级到centos7

热门文章

  1. axure9轮播图做法与按钮思路
  2. 图片按比例缩放,鼠标滚轮调整大小
  3. [线段树分治][DP] LOJ #534. 「LibreOJ Round #6」花团
  4. 手机谷歌翻译位置服务器,谷歌翻译更新手机端App:中国用户可无障碍使用
  5. 华为2019开发者大会内容小记
  6. matlab 提取极值,利用matlab 进行极值统计的一个例子——gev 方法.pdf
  7. BootStrap4登录表单验证示例
  8. 将页面表格导出为excel并下载
  9. 【v-on】一个元素绑定多个事件以及一个事件绑定多个函数的两种写法
  10. 第44件事 用户运营的5个关键环节