自己搭建git 代码服务器

使用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 remote add origin [email protected]:/home/git/work/project.git (即:用户名@网络地址:/home/git/work/project.git)

然后执行: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登录。

然后:

[email protected]:~/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 [email protected]:/home/git/work/project.git
* [new branch] master -> master
[email protected]:~/linux-2.6$ ls

就好了。

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

[email protected]:~$ git clone [email protected]:/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
[email protected]:~$

同样执行一下:
[email protected]:~$ ssh localhost -o StrictHostKeyChecking=no

然后:

[email protected]:~$ git clone [email protected]:/home/git/work/project.git
Initialized empty Git repository in /home/b/project/.git/
[email protected]‘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.
[email protected]:~$ ls
examples.desktop project
[email protected]:~$ ls
examples.desktop project
[email protected]:~$
[email protected]:~$
[email protected]:~$ cd project/
[email protected]:~/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可能不会检查公钥的正确性就让登录了。

时间: 2024-08-10 15:09:16

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

搭建git代码服务器

在代码管理中,通常需要使用版本管理工具,git就是一个不错的选择,这里简单罗列一下git服务器的搭建过程. 1. 安装git工具包 2. 初始化git库:在代码服务器上,通常只需要创建一个不含有工作目录的空仓库,使用命令, git --bare init 创建完成之后,可以看到生成的文件 HEAD  branches    config    description  hooks  info  objects  refs 3. git库创建OK之后,可以将空库clone到本地 git clone

利用树莓派3b搭建git代码服务器

在树莓派上3b的操作,可以利用ssh进行登陆操作: 添加一个"Git"用户和组 增加git用户和组 adduser --system --shell /bin/bash --gecos 'git version control by pi' --group --home /home/git git 注意:/home/git是这个例子里我使用的文件夹.如果你想使用别的路径,替换下面命令里的"/home/git". 修改Git 用户密码 passwd git 切换到gi

使用gitolite-3.6搭建git镜像服务器

需求: 在外网搭建一台git服务器,大家在任何联网的地方可以向git服务器提交.clone,如果一个仓库特别大,在公司clone一个仓库的时候会使用时间过长,带宽占用等不利的因素,那我们在公司内网搭建一台镜像服务器,clone代码的时候可以从镜像服务器clone,会省很多时间,下面我们开始. 我是参照gitolite官网文档搭建的:http://gitolite.com/gitolite/mirroring.html 环境: 总共3台机器,一台在外网git主服务器(以下称为servser1),一

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

centos服务器下搭建git仓库,使用ssh协议管理仓库代码权限    git官网(http://git-scm.com/) 使用ssh协议: 一.安装git,使用yum install git 或者使用 源码包安装git-2.2.0.tar.gz(https://www.kernel.org/pub/software/scm/git/) 新建git用户与用户组 # useradd git # passwd git 二,新建git仓库(仓库位置自己随用户自己决定,例/var/git/testp

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

今天主要叙述在家里台式机的虚拟机上搭建支持 https 的 ubuntu git 服务器. 实际上,从一个用户请求家里 git 服务器代码,最终完成代码的传输,主要是通过以下的过程: 首先,从外界寻找到连接上互联网的家里的路由器,由路由器发送请求到虚拟机的 host,由 host 发送到虚拟机,由虚拟机的 apache 服务器将 https 请求转化为 git 数据请求发送给 git 服务程序,git 服务器程序拿到数据以后原路返还,下面一点一点的将这个过程说清楚. 第一步:从外界找到家里的路由

VisualSVN搭建svn代码服务器

 第一步,准备好各种所需软件 ①visualSVN,在这里我们用 VisualSVN-Server-2.5.5,在官网下载,或者百度谷歌搜索就行了,也可以去下面的链接直接下载哦: 官网:http://www.visualsvn.com/server/download/ 网盘:http://www.kuaipan.cn/file/id_8825968815059757.html 下载下来的文件是VisualSVN-Server-2.5.5.msi. ②svn客户端,我们使用TortoiseSV

搭建git linux 服务器

假设你已经有sudo权限的用户账号,下面,正式开始安装. 第一步,安装git: for Ubuntu或Debian $ sudo apt-get install git for Centos 更新一下 yum 源yum list git 查看可安装版本yum install git 安装 第二步,创建一个git用户,用来运行git服务: $ sudo adduser git 第三步,创建证书登录: 收集所有需要登录的用户的公钥,就是他们自己的id_rsa.pub文件,把所有公钥导入到/home/

mac os 利用ssh 搭建git server服务器详细教程,以及git基本用法

详细讲mac 连接mac的git操作 首先在服务端上 第一:新建一个仓库 1, cd /Users/userName/projects 用linux命令进入一个你想要创建与他人共享的文件夹. 2,sudo git --bare init 建立一个git仓库. ”git init –bare”方法创建一个所谓的裸仓库,之所以叫裸仓库是因为这个仓库只保存git历史提交的版本信息,而不允许用户在上面进行各种git操作,如果你硬要操作的话,只会得到下面的错误(”This operation must b

搭建git 代码同步平台

下载安装githttps://git-scm.com/download/win 1.安装git 指定变量路径 3.设置 > 用户设置 >打开代码 4.找到git配置 在设置区域设置,这里只读 5.进入项目目录 右键选择git bash 6.执行下面命令创建工作区域 并且将代码拉取到本地仓库git init git remote add origin http://ip:3000/xx.git (xx.git 为你创建的仓库)git pull origin master 5.进行编写 点击 暂存