Build their own git server, configure the public and private key (password is required to address each clone push the issue)

Prerequisites: need your own server (nonsense nag about - -!)

Server systems: CentOS  7, ssh remote login server will not be left out of what Baidu slightly

Service-Terminal

Step 1: Install git

 yum install -y git 

After the installation is complete

Step two: Add a user and password to use git

useradd git   #git your username does not like to define its own, but after the definition, must be replaced by the following git your user name corresponding!

passwd git     # new user password must not skip this step, skip clone back when you are prompted to enter the password is! ! 8-digit password you want more!

Tip: passwd:. All authentication tokens updated successfully proved successful password

Step 3: Create a git repository

Select a directory as your warehouse such as / srv

cd / srv # to enter the Loft directory

git init --bare aa.git # initialize the project test directory

But the owner of the directory is not a git user, we have to change it to git users:

 chown -R git: git aa.git # change user owner, after the change:

Server-side work being done, to the following clients:

Client

Step 1: Install git software  https://git-scm.com/downloads , all the way to the next can be installed complete

After the installation is complete, open git

The second step, set your local user name and email address:

git config --global user.name "myname"
git config --global user.email "[email protected]"

第三步,生成公私钥:

ssh-keygen -t rsa -C "[email protected]"   然后一直按enter;知道出现成功的图案:

id_rsa.pub你面的内容就是我们本电脑的公钥

复制该密钥到服务器端的/home/git/.ssh/authorized_keys文件中

注意:!!!!在/home/git/目录下ls -al 查看是否有.ssh目录!!

如果没有,自己新建一个.ssh目录和authorized_keys文件:

mkdir  .ssh   #创建目录

chown -R git:git .ssh  #修改拥有者

cd .ssh

 touch authorized_keys  #创建keys文件

 chmod 700 authorized_keys #修改文件权限

chown -R git:git authorized_keys#修改文件拥有者

第四步:把客户端电脑生成的密钥复制到authorized_keys文件中:

vim authorized_keys

然后按a,插入密钥,然后按ESC键,再输入  :wq    保存退出(也可以用winscp或者其他编辑器把密钥添加进去)

注意!!每个密钥占一行,如果想添加多个客户端电脑需要换行再添加下一个用户!

设置基本完成了,下面进行验证:

git clone git@服务器地址:/srv/aa.git   

出现下面提示证明成功了,注意:可能第一次clone 需要密码,成功之后就不需要每次输入密码,如果每次clone 或者push都需要密码肯定上面某个步骤错了,或者git用户权限不够,密钥填写格式错误,密钥文件和.ssh放置的目录不正确,要仔细检查一下。

本人专业水平有限,有什么错漏的地方请大神们指正,非常感谢。

 

 

 

 

 

发布了38 篇原创文章 · 获赞 10 · 访问量 10万+

Guess you like

Origin blog.csdn.net/winux123/article/details/103639686