使用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. Dispatch Queue 之 Invoke 当前队列

  2. 机器学习与Tensorflow(7)——tf.train.Saver()、inception-v3的应用

    1. tf.train.Saver() tf.train.Saver()是一个类,提供了变量.模型(也称图Graph)的保存和恢复模型方法. TensorFlow是通过构造Graph的方式进行深度学习 ...

  3. Spring Bean 的生命周期,如何被管理的?

    定义 Bean是一个被实例化,组装,并通过Spring IOC容器(BeanFactory和ApplicationContext容器)所管理的对象. 作用域 Spring支持五个作用域,分别是sing ...

  4. 递归查询区域信息及子区域到advTree

    效果: DataTable dtArea = new DataTable(); private void Form1_Load(object sender, EventArgs e) { Node n ...

  5. Java排序方法sort的使用详解(转)

    一.对数组的排序: //对数组排序 public void arraySort(){ int[] arr = {1,4,6,333,8,2}; Arrays.sort(arr);//使用java.ut ...

  6. 关于loading

    在开发中,不可避免的会需要loading的出现,来提高用户体验, 自己在查找中,总结了两条: 1.window.onload的时候显示loading,首先loading图片是一直存在的,window. ...

  7. Jenkins系列之二——centos 6.9 + JenKins 安装

    centos 6.9 + JenKins 安装记录环境: [root@localhost ~]# cat /etc/issue CentOS release 6.9 (Final) Kernel \r ...

  8. SpringBoot集成Redis

    1.引入 spring-boot-starter-redis <dependency> <groupId>redis.clients</groupId> <a ...

  9. Python机器学习笔记:利用Keras进行分类预测

    Keras是一个用于深度学习的Python库,它包含高效的数值库Theano和TensorFlow. 本文的目的是学习如何从csv中加载数据并使其可供Keras使用,如何用神经网络建立多类分类的数据进 ...

  10. ThreadPoolExecutor代码解析

    派生体系 java.util.concurrent ThreadPoolExecutor AbstractExecutorService ExecutorService Executor   这个类是 ...