Setup Git Server in CentOS 6.3

來源:互聯網
上載者:User

標籤:

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>>

 

Setup Git Server in CentOS 6.3

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.