zoukankan      html  css  js  c++  java
  • Linux笔记 #06# 在VPS上自建Git服务

    参考:

    GitHub Help: Connecting to GitHub with SSH

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

    菜鸟教程: Git 服务器搭建

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

    本地( Debian 8.8):

    sudo apt-get install git
    
    git 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

  • 相关阅读:
    Log4net在类库中调用写法
    ruby问题
    C#获取项目程序路径的方法
    Redis数据类型
    WCF身份验证之用户名密码认证
    Log4Net 配置和使用
    Windows 下配置ruby on rails环境
    动态网页转静态化的方法
    如何确认Devkit是否安装成功
    AS400中加入各种颜色
  • 原文地址:https://www.cnblogs.com/xkxf/p/8510817.html
Copyright © 2011-2022 走看看