使用git服务器的工程师都需要生成一个ssh的公钥

~/.ssh$ ssh-keygen
Generating public/private rsa key pair.
……………………
……………………
然后一律按回车,完成后会在home目录下的.ssh目录中生成两个文件id_rsa(私有密钥)和id_rsa.pub(公钥)。
将生成的公钥id_rsa.pub发给git仓库的管理者。
 
然后在服务器端:
sudo adduser git
su git
cd ~
mkdir .ssh
在git用户新建一个.ssh的目录,将开发者的SSH公钥添加到git这个用户的authorized_keys这个文件当中。如有zhangsan,lisi两个开发者。
cat /tmp/id_rsa_zhangsan.pub >> ~/.ssh/authorized_keys
cat /tmp/id_rsa_lisi.pub >> ~/.ssh/authorized_keys
 
建立一个空的仓库
cd work
mkdir project.git
cd project.git
git --bare init
使用--bare会初始化一个不带任何工作目录的仓库,不会看到工程源码。
 
开发者端:
若没有仓库的情况下,需要首先新建一个仓库。在需要建立仓库的,目录下执行以下的命令。
cd my_project
git init
git add . (将所有代码加入工程管理)
git commit -m "xxx project initial commit"
然后执行:git push origin master
如果出现以下错误:

The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is eb:e3:e2:36:84:64:23:f2:b8:7b:a0:4c:ef:d4:9e:7d.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.

执行一下:$ssh localhost -o StrictHostKeyChecking=no

(用ssh登录一下就好使,就不会弹出The authenticity of host 'localhost (::1)' can't be established.的错误了。)

然后再退出ssh登录。

然后:

a@ubuntu:~/linux-2.6$ git push origin master
Counting objects: 56913, done.
Compressing objects: 100% (56081/56081), done.
Writing objects: 100% (56913/56913), 150.96 MiB | 4.08 MiB/s, done.
Total 56913 (delta 4433), reused 0 (delta 0)
To git@localhost:/home/git/work/project.git
* [new branch] master -> master
a@ubuntu:~/linux-2.6$ ls

就好了。

小组内开发者b下载代码时:

b@ubuntu:~$ git clone git@localhost:/home/git/work/project.git
Initialized empty Git repository in /home/b/project/.git/
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is eb:e3:e2:36:84:64:23:f2:b8:7b:a0:4c:ef:d4:9e:7d.
Are you sure you want to continue connecting (yes/no)?
Host key verification failed.
fatal: The remote end hung up unexpectedly
b@ubuntu:~$

同样执行一下:
b@ubuntu:~$ ssh localhost -o StrictHostKeyChecking=no

然后:

b@ubuntu:~$ git clone git@localhost:/home/git/work/project.git
Initialized empty Git repository in /home/b/project/.git/
git@localhost's password:
remote: Counting objects: 56913, done.
remote: Compressing objects: 100% (51648/51648), done.
remote: Total 56913 (delta 4433), reused 56913 (delta 4433)
Receiving objects: 100% (56913/56913), 150.96 MiB | 13.48 MiB/s, done.
Resolving deltas: 100% (4433/4433), done.
Checking out files: 100% (53646/53646), done.
b@ubuntu:~$ ls
examples.desktop project
b@ubuntu:~$ ls
examples.desktop project
b@ubuntu:~$
b@ubuntu:~$
b@ubuntu:~$ cd project/
b@ubuntu:~/project$ ls
arch crypto include kernel net security
block Documentation init lib README sound
certs drivers ipc MAINTAINERS REPORTING-BUGS tools
COPYING firmware Kbuild Makefile samples usr
CREDITS fs Kconfig mm scripts virt

分析 ssh localhost -o StrictHostKeyChecking=no可能不会检查公钥的正确性就让登录了。

 

自己搭建git 代码服务器的更多相关文章

  1. 搭建git代码服务器

    在代码管理中,通常需要使用版本管理工具,git就是一个不错的选择,这里简单罗列一下git服务器的搭建过程. 1. 安装git工具包 2. 初始化git库:在代码服务器上,通常只需要创建一个不含有工作目 ...

  2. 搭建Git本地服务器

    搭建Git本地服务器 参考文章:http://www.ossxp.com/doc/git/gitolite.html 当前任务,学习中... 公司小范围用法: 服务器上做的: .在服务器上建立一个用户 ...

  3. git 代码服务器的网页版gitweb的搭建

    sudo apt-get install apache2 git-core gitwebsudo a2enmod rewrite #vi /etc/gitweb.conf $projectroot = ...

  4. 在家用机上搭建 Git https 服务器

    今天主要叙述在家里台式机的虚拟机上搭建支持 https 的 ubuntu git 服务器. 实际上,从一个用户请求家里 git 服务器代码,最终完成代码的传输,主要是通过以下的过程: 首先,从外界寻找 ...

  5. 搭建git远程服务器三步骤

    以前都是使用git,这次由于工作需要,需要自己搭建一个远程git服务器.根据网上的 介绍,捣鼓了一下午,终于把远程git服务器搞定了,这里,做个总结. 搭建git远程服务,首先要安装git和ssh,以 ...

  6. CentOS 6.8 搭建 Git 代码托管系统 Gitea

    [荐] Gitea:Git with a cup of tea,在 Gogs 基础上,发展起来的 自助 Git 服务系统.Gogs是一个个人维护的版本,而Gitea是一个社区组织维护的,版本迭代更新快 ...

  7. CENTOS下搭建git代码仓库 ssh协议

    centos服务器下搭建git仓库,使用ssh协议管理仓库代码权限    git官网(http://git-scm.com/) 使用ssh协议: 一.安装git,使用yum install git 或 ...

  8. win7本地搭建git ssh服务器

    本来是想在gogs上用ssh的,结果弄了好几次还没整明白,希望等他们的更新内置吧. 但是,意外收获,还是成功搭建了本地ssh服务器,只是没有和gogs成功关联. 简要记录一下: 主要软件: msysg ...

  9. Linux 上搭建 git 的服务器

    搭建服务器 假设服务器的名字是 git.example.com. 首先,添加一个叫做git的用户adduser git. 然后如果不存在的话, 为这个用户新建一个主目录mkdir /home/git, ...

随机推荐

  1. spring boot 访问静态资源的步骤

    1)resources/static下放置html文件.(或者static下新建目录 http://hcss:8090/imgs/单例.png) 2)webapp下放置html文件. 如果两个路径下有 ...

  2. python学习记录(一)

    1.打印操作 >>> print('hello') hello >>> print(1+2) 3 2.字符串操作 ① ') Traceback (most rece ...

  3. 启动elasticsearch报错

    could not find java; set JAVA_HOME or ensure java is in PATH 首先需要安装java 1.yum list installed |grep j ...

  4. maven-assembly-plugin的使用

    maven-assembly-plugin使用描述(拷自 maven-assembly-plugin 主页) The Assembly Plugin for Maven is primarily in ...

  5. Spring Cloud Ribbon——客户端负载均衡

    一.负载均衡负载均衡(Load Balance): 建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备和服务器的带宽.增加吞吐量.加强网络数据处理能力.提高网络的灵活性和可用性.其意思 ...

  6. 通过jenkins API去build一个job

    背景 查看jenkins的api 直接访问 JENKINS_URL/job/JOB_NAME/api/ 就可以查看jenkins的api build一个job的话,是POST请求 JENKINS_UR ...

  7. 进程间通信IPC-命名管道FIFO

    FIFO又被称为命名管道,未命名的管道只能在两个相关的进程之间使用,而这两个相关的进程还要有一个共同创建了它们的祖先进程,但是FIFO,不相关的进程之间也能交换数据. FIFO是一种文件类型.通过st ...

  8. filter listener interceptor的区别

    转自: http://www.cnblogs.com/shangxiaofei/p/5328377.html https://www.cnblogs.com/jinb/p/6915351.html 一 ...

  9. 使用shell脚本来自动化处理我们的工作,解放双手

    Shell脚本介绍 1.Shell脚本,就是利用Shell的命令解释的功能,对一个纯文本的文件进行解析,然后执行这些功能,也可以说Shell脚本就是一系列命令的集合. 2.Shell可以直接使用在wi ...

  10. [AGC 018 E] Sightseeing plan

    STO ZKY ORZ Description 给定一张网格图和三个矩形,每次只能向上或向右走.你需要从矩形 \(A\) 中的一个点 \(S\) 出发,到达矩形 \(B\) 中的一个点 \(P\) , ...