linux build a remote git repository

Create a user on the server side git for Git management services, and set a password for the user git

id git# See if the user exists
useradd git# add a user
passwd git# password

Server-side to create a Git repository

gittest.git name for the warehouse, Git repository on the server usually end with .git. gittest is the work zone clone down, so the best is the project name.

[root@localhost home]# mkdir -p data/git/gittest.git
[root@localhost home]# git init --bare data/git/gittest.git
Initialized empty Git repository in /home/data/git/gittest.git/
[root@localhost home]# cd data/git/
[root@localhost git]# chown -R git:git gittest.git/

Creating SSH Key

### When you first use the clone Git commands or push connection, will get a warning:

The authenticity of host 'github.com (xx.xx.xx.xx)' can't be established.
RSA key fingerprint is xx.xx.xx.xx.xx.
Are you sure you want to continue connecting (yes/no)?

### This is because Git uses SSH connection, and when the first SSH connection verification Key GitHub server, you need to confirm whether the fingerprint information Key's GitHub GitHub really from the server, enter yes press Enter.

Git will output a warning, telling you have to add GitHub is Key to a trusted list of this machine in the:

Warning: Permanently added 'github.com' (RSA) to the list of known hosts.

This warning will only appear once, the latter operation will not have any warning.
If you are really worried about people posing as GitHub server, you can use SSH public key to complete the verification.

ssh-keygen -t rsa -C "[email protected]"  
 #创建 ssh-key

Git server opens RSA authentication

First, the server needs Git / etc / ssh / sshd_config RSA authentication will be opened, removing the three rows in front of the following comments.

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile  .ssh/authorized_keys

[Save] and restart sshd service

/etc/rc.d/init.d/sshd restart

AuthorizedKeysFile informed by the public key storage path is .ssh / authorized_keys, is actually $ Home / .ssh / authorized_keys, due to the Git user management services that git, so the path actually stored public key is /home/git/.ssh / authorized_keys
create a directory under / home / git / .ssh

mkdir .ssh
chown -R git:git .ssh

[The client public key import the file server /home/git/.ssh/authorized_keys]
back to the next Git Bash, import the file:

ssh [email protected] 'cat >> .ssh/authorized_keys' < ~/.ssh/id_rsa.pub

Modify the corresponding file permissions]

chmod 700 .ssh
chmod 600 authorized_keys

The client again clone a remote repository

git clone [email protected]:/home/data/git/gittest.git

# The other operation is the same

Prohibit git user ssh login server

Edit / etc / passwd file
[found] git:x:502:504::/home/git:/bin/bash[] to amendgit:x:502:504::/home/git:/bin/git-shell

Guess you like

Origin blog.csdn.net/xianhenyuan/article/details/92794974