Setup Git Server in CentOS 6.3

Source: Internet
Author: User
Tags setup git server ssh server

0. Environment:

Server Machine:centos 6.3 x86

Client machine:windows Pro x86_64

1. Install SSH Server

[Server machine Shell]
#Yuminstall 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

/home/git--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]>"[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 have been saved In/c/users/<your account Name>/.ssh/id_rsa.
Your public key had 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  . SSH $CD. SSH $ Touch Authorized_keys
$chmod Authorized_keys

Sample output

The authenticity of host ' <server address> (<server address>) ' can ' t be established.
RSA key fingerprint is sha256:hsflk18mlwp3wtnvgkcbrzijzmvcjsdlhjg/span9z0.
Is you sure 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 07:58:35 from <client ip>
[[email protected] ~]$ mkdir. SSH
[Email protected] ~]$ chmod. SSH
[[Email protected] ~]$ CD. SSH
[email protected]. ssh]$ Touch Authorized_keys
[email protected]. ssh]$ chmod Authorized_keys

Append client ' public key to server ' s Authorized_keys file by Copy-and-paste

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 then         Save >git add readme.md"Intial commit for Sample project">git push origin Master

8 done. If you want to the submit code in another. 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 to 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, the user still can user name git to push their the code to server, but the login via SSH is denied

C:\users\<account name>>ssh [Email protected]<server address>
Last Login:sun Oct 10:42:30 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.