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. HDOJ 4883 TIANKENG’s restaurant

    称号: TIANKENG's restaurant Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Ja ...

  2. NET Platform Standard

    NET Platform Standard 相关博文:ASP.NET 5 Target framework dnx451 and dnxcore50 .NET Platform Standard:ht ...

  3. String[255]在高版本Delphi里还是被解释成Byte,总体长度256,使用StrPCopy可以给Array String拷贝字符串(内含许多实验测试)

    学了好多不了解的知识: procedure TForm1.Button1Click(Sender: TObject); var s1 : String; s2 : String[]; begin s1 ...

  4. Hook任务栏时钟窗口(原理其实很简单,就是注入DLL到时钟窗口进程(explorer.exe))

    用过一些日历软件的小伙伴应该都知道它们都实现了在时钟窗口上的Hook,也就是屏蔽了系统原有的功能,实现自己的功能 某日历软件Hook时钟窗口后的效果 经过一番研究,发现原理其实很简单,就是注入DLL到 ...

  5. C/C++中constkeyword

    今天在做一个趋势笔试题的时候.才让我有了系统把constkeyword好好总结一下的冲动,由于这个关键词大大小小好多地方都出现过,出现频率很高,而每次仅仅是简短的把答案看了一下,没有真正将其整个使用方 ...

  6. Flume+LOG4J+Kafka

    基于Flume+LOG4J+Kafka的日志采集架构方案 本文将会介绍如何使用 Flume.log4j.Kafka进行规范的日志采集. Flume 基本概念 Flume是一个完善.强大的日志采集工具, ...

  7. Latin1的所有字符编码

    ISO-8859-1 (ISO Latin 1) Character Encoding Contents The characters at a glance Character codes and ...

  8. 16位图像Alpha混合的实现(用汇编写的,比MMX还要快)

    Alpha 混合的算法很简单,基于下面的公式就可以实现: D := A * (S - D) / 255 + D D 是目标图像的像素, S 是源图像的像素 A 是 Alpha 值, 0 为全透明, 2 ...

  9. [Android学习笔记]view的layout过程学习

    View从创建到显示到屏幕需要经历几个过程: measure -> layout -> draw measure过程:计算view所占屏幕大小layout过程:设置view在屏幕的位置dr ...

  10. 使用KnockoutJs+Bootstrap实现分页

    [后端人员耍前端系列]KnockoutJs篇:使用KnockoutJs+Bootstrap实现分页   一.引言 由于最近公司的系统需要改版,改版的新系统我打算使用KnockoutJs来制作Web前端 ...