Linux下基于SSH协议GIT服务器搭建实例

第一:关于SSH的设置

1、  在客户端

[root@ www.linuxidc.net ~]# ssh-keygen   //生成公匙和密匙

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory '/root/.ssh'.

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:

af:7a:4c:de:69:7d:5d:4c:74:41:2f:4b:9a:9f:69:08 root@ www.linuxidc.net

[root@ www.linuxidc.net ~]# scp .ssh/id_rsa.pub 192.168.1.193:/root  //把自己的公匙上传到服务器

The authenticity of host '192.168.1.193 (192.168.1.193)' can't be established.

RSA key fingerprint is 0a:54:06:f8:28:41:bd:cd:bd:e6:fa:ae:de:56:24:78.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added '192.168.1.193' (RSA) to the list of known hosts.

[email protected]'s password:

id_rsa.pub                                    100%  396     0.4KB/s   00:00

2、在服务器端的设置

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Created directory '/root/.ssh'.

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:

第二:关于git安装和配置

1、  在服务器端和客户端的公共配置

git-1.7.7.4.tar.gz

source ~/.git-completion.bash

2、  在服务器端仅有的操作

Initialized empty Git repository in /opt/git/mygit/

3、  在客户端的操作

[root@ www.linuxidc.net ~]# mkdir /git

[root@ www.linuxidc.net ~]# cd /git/

[root@ www.linuxidc.net git]# git init

Initialized empty Git repository in /git/.git/

[root@ www.linuxidc.net git]# vim README

 

Hello ethnicitybeta!

[root@ www.linuxidc.net git]# git add .

[root@ www.linuxidc.net git]# git commit -m "1st commmit"

[master (root-commit) e28450f] 1st commmit

 1 files changed, 1 insertions(+), 0 deletions(-)

 create mode 100644 README

[root@ www.linuxidc.net git]# git remote add origin 192.168.1.193:/opt/git/mygit 

[root@ www.linuxidc.net git]# git push origin master   //把自己的修改提交给服务器

Counting objects: 3, done.

Writing objects: 100% (3/3), 221 bytes, done.

Total 3 (delta 0), reused 0 (delta 0)

To 192.168.1.193:/opt/git/mygit

 * [new branch]      master -> master

第三:关于权限的设定

这里设置只有有权限的人可以浏览修改,其他人不可以

git:x:501:501::/home/git:/bin/bash/git-shell

这样就可以了

 总结:git学习笔记。

相关推荐