当前位置:首页 > CN2资讯 > 正文内容

Linux笔记 #06# 在VPS上自建Git服务

4天前CN2资讯

 

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

本地( Debian 8.8):



sudo apt-get install git

git version # 确保正确安装



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


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



root@xkfx:~# ssh-keygen -t rsa -C "little_fish@"
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@ # 已改,仅作示范
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@



[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@

The authenticity of host ' (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 ',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.idchg.com/info/19323.html

    分享给朋友:

    “Linux笔记 #06# 在VPS上自建Git服务” 的相关文章

    普通人能否使用CN2线路电缆?深度解析其适用性与价值

    CN2线路电缆的特点与应用场景CN2线路电缆,全称为“中国下一代互联网传输网络”(ChinaNextGenerationNetwork),是中国电信为提升国际网络性能而建设的高带宽、高质量传输网络。它是我国为了满足国际通信日益增长的需求而推出的重要项目,旨在提供更高效的国际网络连接服务。对于普通人来...

    ChicagoVPS 测评:性能、价格与客户服务的全面分析

    在开始谈论ChicagoVPS之前,我想分享一些关于它的背景故事。ChicagoVPS成立于2010年,源于对高效和可靠的虚拟专用服务器(VPS)的需求。作为一家快速崛起的公司,它在短短几年内就积累了相当可观的用户基础。它在美国中西部的沃土上发展壮大,吸引了不少希望获得优质服务的用户。公司的愿景是提...

    深入了解DC9飞机的历史、技术特点与运营经验

    DC9概述 了解DC9这款飞机,首先得从它的历史说起。DC9,或称道格拉斯DC-9,是由道格拉斯飞机公司设计制造的中短程单通道喷气式客机。这款飞机的诞生可以追溯到20世纪60年代。道格拉斯公司在这段时间逐步崛起,骄傲地推出了DC9作为回应当时日益增长的民航市场需求。最初的设计版本虽然体积不大,但凭借...

    恒创科技:引领数据中心与网络安全解决方案的先锋

    恒创科技这个名字,对于熟悉科技行业的人来说,或许并不陌生。它是一个多元化的品牌,涉及数据中心、网络安全、软件开发和智慧城市解决方案等多个领域。我对这家公司一直抱有浓厚的兴趣,因为它所提供的服务非常全面,能够满足不同行业的需求。 在我看来,恒创科技一直努力将最先进的技术应用于实际场景中,尤其是在互联网...

    VPS搭建:从选择提供商到后续管理的全面指南

    什么是VPS搭建? 了解VPS搭建的第一步是弄清楚VPS的定义。VPS,全称为虚拟专用服务器,是将一个物理服务器划分成多个独立的虚拟服务器。每个VPS都具有自己的操作系统和资源,能够像独立服务器一样运行各种应用程序。这种方式提供了更高的灵活性和可控性,相比共享主机来说,用户能够自主安装软件,配置环境...

    RackNerd Windows VPS的硬件条件与性能评测

    在选择虚拟服务器服务商时,硬件条件是我最关注的部分。RackNerd作为一家提供多种配置Windows VPS的服务商,其硬件条件非常吸引。接下来,我将详细介绍RackNerd在硬件配置方面的一些关键特点。 处理器配置 RackNerd使用的AMD Ryzen 3900X处理器,让人印象深刻。这个处...