Setup Git Server in CentOS 6.3

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 "[email protected]"

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 [email protected]
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 [email protected]<server address>

$midkr .ssh
$chmod 700 .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.
[email protected]<server address>‘s password:
Last login: Sun Oct 18 07:58:35 2015 from <client ip>
[[email protected] ~]$ mkdir .ssh
[[email protected] ~]$ chmod 700 .ssh
[[email protected] ~]$ cd .ssh
[[email protected] .ssh]$ touch authorized_keys
[[email protected] .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

[[email protected] ~]$ vi .ssh/authorized_keys

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 [email protected]<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 user name git to push their code to server, but login via ssh is denied

C:\Users\<account name>>ssh [email protected]<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>>

时间: 2024-08-11 05:45:58

Setup Git Server in CentOS 6.3的相关文章

setup FTP server on CentOS 7

https://www.unixmen.com/install-configure-ftp-server-centos-7/ vsftpd (Very Secure File Transport Protocol Daemon) is a secure, fast FTP server for Unix/Linux systems. # install vsftp yum install vsftpd -y #edit config file and ## disable anonymous l

Setup FTP Server step by step in CentOS / RHEL / Scientific Linux 6.3/6.4/6.5

https://ostechnix.wordpress.com/2013/12/15/setup-ftp-server-step-by-step-in-centos-6-x-rhel-6-x-scientific-linux-6-x/ This tutorial shows you how to install and configure FTP server in CentOS 6.5. Though the steps provided here are tested in CentOS 6

centos 安装git server

1.yum install lrzsz wget git 2.安装gitosis:gitosis为Git用户权限管理系统,通过管理服务端的/home/git/.ssh/authorized_key文件来执行对用户权限的管理,是一个python模块包 #yum install python python-setuptools #git clone git://github.com/res0nat0r/gitosis.git #cd gitosis/ #python setup.py install

centos 安装http协议的git server

1.服务器端安装httpd,git,gitweb等 1 #yum install httpd git git-daemon  gitweb 2.服务器端初始化仓库 1 2 3 #mkdir -p /data3/gitserver #cd /data3/gitserver #git init --bare git_repo #初始化一个裸仓库 3.向裸仓库提交初始文件 1 2 3 4 5 6 7 #cd /tmp #git clone /data3/gitserver/git_repo #cd g

在centos中搭建基于smart http的git server

# 由于公司的特殊需求,需要将git集成到IBM的RTC里面,而RTC使用的是http,所以要只能放弃了git原生的ssh,转而使用smart http,git server搭建在centos系统上.博主在浏览了N多教程发现都是比较残缺的,并没有针对smart http的特殊需求,有一篇相对完整的但也有几个坑(博主为了填这几个坑吐了好多口老血,因此决定把教程记录到博客上防各位不时之需,该教程针对像博主这样的非专业运维的developer的手把手教程,欢迎指正!) 以下是主要的环境参数 系统lin

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.github.io/git/linux/2016/03/30/git-over-http-by-nginx.html 参考:http://beginor.github.io/2016/03/12/http-git-server-on-nginx.html ? Downgrade Lightroom 5 c

Git Server搭建

本文原文出处: http://blog.csdn.net/bluishglc/article/details/49310125 严禁任何形式的转载,否则将委托CSDN官方维护权益! 1 参考 所有相关细节均可以从该文档出获取: http://git.oschina.net/progit/4-%E6%9C%8D%E5%8A%A1%E5%99%A8%E4%B8%8A%E7%9A%84-Git.html# 2 安装 Git并不存在Server端和Clint端之分,在Git Server上安装的也还是G

ubuntu Gitolite管理git server代码库权限

公司代码库用Git,全部用SSH认证,多个代码库多个用户,权限管理是个头疼的问题,今天终于有空测试下Gitolite, Gitolite是在Git之上的一个授权层,依托sshd或者httpd来进行认证.(概括:认证是确定用户是谁,授权是决定该用户是否被允许做他想做的事情). Gitolite允许你定义访问许可而不只作用于仓库,而同样于仓库中的每个branch和tag name.你可以定义确切的人(或一组人)只能push特定的"refs"(或者branches或者tags)而不是其他人.

How to install VNC server on CentOS 6

参考: https://rbgeek.wordpress.com/2012/06/26/how-to-install-vnc-server-on-centos-6/ VNC is a protocol that is used to share the desktop with other users/computers over the network/Internet.In order to share a desktop, VNC server must be install and co