在ubuntu上搭建git服务器

1、参考廖雪峰的博客搭建。
2、邮箱名最好和git的邮箱名保持一致。
在客户端生成ssh密钥。

[root@localhost storlead_project]# ssh-keygen -t rsa -C "[email protected]"
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:
ab:9b:80:d1:94:24:5f:67:2d:64:27:b3:14:4c:0f:97 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
|  . . .+%oo.     |
|   + o =oOE      |
|    +   ...      |
|   o             |
|  . .   S        |
|   o     .       |
|  . .   .        |
|     . o         |
|      +.         |
+-----------------+

在服务端添加ssh密钥。
将客户端/root/.ssh/id_rsa.pub里的内容全部复制粘贴到服务端的/home/git/.ssh/authorized_keys 里。

root@StorleadServ:/etc/ssh# cd /home/git/.ssh/
root@StorleadServ:/home/git/.ssh# vim authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAtFnGwBNkgJK2dKFzXGuvSMb+7httfFUBYr072UO9sD4lp2xaDwuIrzpOy6FE5P+JUZxSnOXvFF/aja2ie17M8Fjp/0KUHb5aZ6sjIUur1Am1f5PVmmbx+XFl4xZtJBQLbRYxVmXzI8m+HZZkkNQhpYHxpDNJMGExo0POtgSEXlcN0Wl1gaYSxXB3+xlY4vU6LUWtGuUwJ5D+IrWzSQ7unXi4WWEscwFJIPplvskC1CUVsLI3NKc5eUEL71OcDoi0ar4HULldQj6KdPDOVb8DJiMONr3zb6AUiB/m4xRizyig4mlQWpI5sUTyESVvStOoOI5wvL8wWyfu9D3fMNk1fQ== [email protected]

最好重启服务端的ssh服务。

3、在客户端克隆仓库的时候报错:

[root@localhost storlead_project]# git clone [email protected]:/opt/git/ast2400/sample.git
正克隆到 'sample'...
The authenticity of host '192.168.0.70 (192.168.0.70)' can't be established.
RSA key fingerprint is e2:d2:7f:87:5d:54:b4:0d:f1:74:be:d9:d4:3c:ba:08.
Are you sure you want to continue connecting (yes/no)? 
Host key verification failed.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

修该服务端的ssh配置文件/etc/ssh/ssh_config里的下面两行,然后重启ssh服务。

#   StrictHostKeyChecking no
#   UserKnownHostsFile /dev/null

你可能感兴趣的:(Git)