0. Environment:

Server machine: CentOS 6.3 x86

Client machine: Windows 10 Pro x86_64

1. Install ssh server

[server machine shell]
#yum install openssh openssh-server
#chkconfig sshd on
#/etc/init.d/sshd start

2. Create user git

[server machine shell]
#useradd git
#passwd git

3. Create an empty repository

[server machine shell]
#cd /home/git
#git init --bare sample.git
#chown -R git:git sample.git

4. Conifigure ssh client in client machine

Download Git for Windows from https://git-for-windows.github.io/

Direct link(for 64bit system): https://github.com/git-for-windows/git/releases/download/v2.6.1.windows.1/Git-2.6.1-64-bit.exe

Install it to default location(C:\Program Files\Git), add C:\Program Files\Git\usr\bin to system environment PATH

Adding C:\Program Files\Git\usr\bin to PATH to enable command ssh and ssh-keygen in cmd.exe

Replace the  email address with yours to generate public & private ssh keys

[client machine cmd]
>ssh-keygen -t rsa -C "my_email@hotmail.com"

Press Enter three times to accept default setting, sample output

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/<your account name>/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/<your account name>/.ssh/id_rsa.
Your public key has been saved in /c/Users/<your account name>/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:+GR+6jWy7FtN3hFBszUCq08nk3fzlIBPzI0AbTkwOo4 my_email@hotmail.com
The key's randomart image is:
+---[RSA 2048]----+
|         ++ooo+..|
|        . .=* +=.|
|       o  .o.*o. |
|      o.. . + ...|
|     E..S. =.+.+.|
|       =  o+=..oo|
|        + =.o . .|
|       . B .     |
|       oB.       |
+----[SHA256]-----+

5. Transfer client machine's public key to server machine to enable login without password

[client machine cmd]
>ssh git@<server address> $midkr .ssh
$chmod .ssh
$cd .ssh
$touch authorized_keys
$chmod 600 authorized_keys

Sample output

The authenticity of host '<server address> (<server address>)' can't be established.
RSA key fingerprint is SHA256:hsFlk18MlWP3wtNVGKcBrZijZMvCjsdlhJg/SPAn9Z0.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '<server address>' (RSA) to the list of known hosts.
git@<server address>'s password:
Last login: Sun Oct 18 07:58:35 2015 from <client ip>
[git@localhost ~]$ mkdir .ssh
[git@localhost ~]$ chmod 700 .ssh
[git@localhost ~]$ cd .ssh
[git@localhost .ssh]$ touch authorized_keys
[git@localhost .ssh]$ chmod 600 authorized_keys

Append client's public key to server's authorized_keys file by copy-and-paste

[client machine cmd -> connected to server via ssh]
$vi ~/.ssh/authorized_keys

client machine public key location: %USERPROFILE%\.ssh\id_rsa.pub

server machine authorized_keys file location: /home/git/.ssh/authorized_keys

Sample authorized_keys file

[git@localhost ~]$ vi .ssh/authorized_keys

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAdIAAABgCAIAAAAmd2SrAAAPi0lEQVR4nO2cTW4ryw2FtRzvR5vIFgTYwN3AQ34mGWkrgsYPySijjJydKANbrVKRPDys/pF0fT4Y93VXs8hTLDbdahlvdxFCCLEhu0cLEEKIn4XarhBCbIrarhBCbIrarhBCbIrarhBCbIrarhBCbIrarhBCbIrarhBCbErSdv/6j3+WfrYRLZ6Ev/3xx8v9PDpnQhBt9z///V/085fD39t/1XZ/Gr8+Pl7u59E5E4Jou3/+69/kT9x2P4/7t2/2x8+l1zCP06HXdDq8vT2t3Bi7EJrP4z6e22xen49fHx+/3t9/vb/f+trXaTtoR9ofO36zH5oeXbo6ua3gus8vtMfi9yBvuzsav+1+Hvdvb4fT7fR4cqweh9t2v0dgO1op+mNddU66zftqVdP5p99hPz5+fVz75tQ9P5pO+tGOeM2xt6Gnh5duwr4X+Hncfy9kwS0QgmLttnur7mcFtd3178mnbrufx/3Uot7e3vb7/f74eTkdph2972gfQQuO2u5HP/3D9NDeIZ4eX2r8fC3qurR2mUJsBNt2v60bulO/7YKu23x2vVqcDm/74+l7/HC6mVzvitSgeUHw7fR0eNsfj+bj5HXm/njk2u7p8LY/HK7PfrPF74+fd28zqF9Nt6idiMPJ9Z+4adb+tcxOz+dx//2fyega91tuue0yzfHuQfX+aRdP59ru1zLUdsUDodru5dphvw7af/O261d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CoKi3BjcvYp34iz659N6szi05tQsCi3KvRutyg2INViFXtTJZAcqJLbqAuqJs6sHywOte+Cw1S4R5Hl2ysHdzfSBsYwaduCH7Q9VzSA2Bsfi7nuKAHPLwQvOz5KXotVlrvT0jd00L2ymUjbhnuxXB/xQ1MX1jWmlQFz0zRy7HGen9UAn842mghhBBCCPGzuTxagBBC/CAu138vzakQQogtUM8VQgghhBBCCCGEEEIIIYQQQgghhBBCCCGEEGJp/g8Pu0JhU76ATwAAAABJRU5ErkJggg==" alt="" />

Logout from server and connect again to test, if ssh doesn't prompt for password, your configuration for ssh is correct.

6. Clone remote repository

[client machine cmd]
>git clone git@<server address>:sample.git

7. Test

Create a README.md file and push to server repository

[client machine cmd]
>touch README.md
>notepad README.md #input some content into README.md, then save
>git add README.md
>git commit -m "Intial commit for sample project"
>git push origin master

8 Done. if you want to submit code in another machine, you need to:

  a. Append the public key of the new machine to server's authorized_keys file

  b. Clone repository to new machine

  c. Modify the files in new machine local repository, and push to server(remote repository)


If you don't want the user git login into server via shell, you can modify the type of shell for this user

[server machine shell]
#vi /etc/passwd

Locate to the end of file, change  git:**********/bin/bash to git:**********/usr/bin/git-shell

After that, user still can use name git to push their code to server, but login via ssh is denied

C:\Users\<account name>>ssh git@<server address>
Last login: Sun Oct 18 10:42:30 2015 from <client ip>
fatal: What do you think I am? A shell?
Connection to 192.168.1.109 closed.

C:\Users\<account name>>

Setup Git Server in CentOS 6.3的更多相关文章

  1. setup FTP server on CentOS 7

    Setup FTP Server on CentOS 7 Install vsftpd vsftpd (Very Secure File Transport Protocol Daemon) is a ...

  2. Setup FTP Server On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3

    setsebool allow_ftpd_full_access onsetsebool -P ftp_home_dir on vsftpd (Very Secure File Transport P ...

  3. 搭建Git Server - Centos+Gitosis

    参考并部分转载自:http://www.pfeng.org/archives/757 1. 安装依赖 yum -y install curl-devel expat-devel gettext-dev ...

  4. Setup VSFTPD Server with Virtual Users On CentOS, RHEL, Scientific Linux 6.5/6.4/6.3

    We have already shown you How to Setup VSFTPD Server on CentOS 6.5/6.4 in our previous article. In t ...

  5. Setup a private http/nginx based GIT server

    原文:http://aaba.me/blog/2014/03/setup-a-private-http-nginx-based-git-server.html https://doomzhou.git ...

  6. centos git server 的搭建

    安装环境  centos7 说明:centos  yum 库里面的git  好像是不区分 客户端和服务器端, 安装 git 以后 就可以创建  仓库,也可以检出 别的 git 仓库的  代码了.所以不 ...

  7. Installing MySQL Server on CentOS

    MySQL is an open-source relational database. For those unfamiliar with these terms, a database is wh ...

  8. Ubuntu server 搭建Git server

    Ubuntu server 搭建Git server,git相比svn,最主要就是分布式了,每个客户端用户的本地都是一个版本管理控制器. Ubuntu server 版本为12.04 搭建步骤如下: ...

  9. IP Failover Setup using Keepalived on CentOS/Redhat 6

    source url:http://tecadmin.net/ip-failover-setup-using-keepalived-on-centos-redhat-6/ Keepalived is ...

随机推荐

  1. Swift - 文本输入框内容改变时响应,并获取最新内容

    1,问题描述 有时我们开发的时候需要先把“确认”按钮初始设置为不可用,当文本框中输入文字以后,再将输入按钮变为可用. 2,实现原理 (1)要检测文本框内容的变化,我们需要让新界面的Controller ...

  2. python 时间戳 datetime string 转换

    import datetime import time **datetime转时间戳** In [1]: now = datetime.datetime.now() In [2]: time.mkti ...

  3. ListView数据动态刷新

    在Android开发中用到ListView时,经常遇到要更改ListView内容的情形,比如删除或增加ListView中显示的条目,这里给大家提供一下思路:不论ListView要显示的对象是什么(如: ...

  4. TForm.ShowModal只是接管消息循环,禁止外部键盘和鼠标输入到别的窗口,但并不封锁其它窗口继续获取消息(比如WM_TIMER消息仍可被发送到别的窗口上)

    窗体上放一个TTimer,然后双击输入: procedure TForm1.Timer1Timer(Sender: TObject); var cvs: TCanvas; Rect: TRect; S ...

  5. Delphi数据类型转换(有几个字符串函数没见过,比如StringToWideChar和WideCharToString)

    DateTimeToFileDate                  函数                     将DELPHI的日期格式转换为DOS的日期格式         DateTimeT ...

  6. 菜鸟玩云计算之十一:Hadoop 手动安装指南

    Hadoop 手动安装指南 cheungmine 2013-4 本文用于指导在Windows7,VMWare上安装Ubuntu, Java, Hadoop, HBase实验环境. 本指南用于实验的软件 ...

  7. C语言中字符串如何转换为二进制、八进制、十进制、十六进制

    在C语言某个程序当中需要把文本16进制转换成对应的16进制数,比如字符串"0x1a"转换成10进制的26,可以用以下函数来实现 相关函数: atof, atoi, atol, st ...

  8. Oracle Client: TNS: Connect timeout ocurred.

    1. 检查Oracle Server 的防火墙是否关闭. 2. Client, Server 重启.

  9. Android-1-电话拨号程序

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjY1MTM4OQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...

  10. swift 简单语句 控制流语句

    在 Swift 中.有两种类型的语句:简单语句和控制流语句.简单语句是最常见的.用于构造表达式和声明.控制流语句则用于控制程序运行的流程,Swift 中有三种类型的控制流语句:循环语句.分支语句和控制 ...