Git-- initial setup [A]

Git client work

After installation, you need to set the final step in the command line input

$ git config --global user.name "Your Name"
$ git config --global user.email "[email protected]"

Check the user name and user mailboxes

$ Git config user.name view the user name 
$ git config user.email View user's mailbox

Modify the user name and user mailboxes

Git config $ - , Ltd. Free Join user.name " username "     to modify the user name 
$ git config - , Ltd. Free Join user.email " Email "     modify user mailboxes

Create a local Git repository, create an empty folder, Git Bash Here

$ git init
Initialized empty Git repository in /Users/michael/learngit/.git/

Creating local public and private keys

SSH-keygen $ - t rsa 
# Next, three carriage returns to default

The locally generated public key to upload the Git server .ssh / down.

 

Git server-side work

# 1 . Switch to the account git 
$ git su 
# 2 . Git into the account's home directory 
$ cd / Home / git 

# 3 . Create a .ssh configuration, if this folder already exists, please ignore this step. 
Mkdir .ssh $ 

# 4 . .Ssh into the directory you just created and create authorized_keys file, which is stored ssh client remote access of the public. 
Cd $ / Home / git / .ssh 
$ Touch authorized_keys 

# 5 . Set permissions, this step can not be omitted, but do not change the value of the rights, or will be error. 
Chmod $ 700 /home/git/.ssh/ 
$ chmod 600 /home/git/.ssh/authorized_keys
Switch to the server side, add the contents laoma.pub just upload the file to the authorized_keys, it can allow the client to access the ssh. 

Switch to the account # git 
$ git su 
$ cd / Home / git / .ssh 

$ LS - Al 
# check whether there .ssh directory and authorized_keys file liangyadong.pub 
#. 
# | - authorized_keys 
# ` - liangyadong.pub 

# If so, be added to the contents of laoma.pub file authorized_keys in the following. 
$ CAT liangyadong.pub >> authorized_keys 

# >> is appended to the file means, mainly if other editors, each of ssh pub to a single line, it is recommended simply use the cat command easy.

 

Git client test

# Client to connect to remote server using ssh test, set the domain name aicoder.com into your ip address or domain name 
$ ssh [email protected]     

# for the first time connected to the warning, enter yes to continue. If you can connect on, then congratulations, your ssh configuration has it.


禁止Git客户端通过shell登录服务器端

Because we added in front of the client's public key to the remote ssh server, so the client can log in directly through the shell on the remote server, which is not safe, not what we want. Let us look at how to disable shell login below:

The first step:
to  /home/git the following to create a git-shell-commandsdirectory, and the owner of the directory is set to git account. It can operate directly with the git account to log terminal server.

Go water $ 
$ mkdir / home / go / no-go-shell commands

This folder is git-shell used in the directory, we need to manually create, otherwise error: fatal: Interactive git shell is not enabled hint:. ~ / Git-shell-commands should exist and have read and execute access.

Step two: modify the /etc/passwdfile, modify

Vim $ / etc / passwd 

# can quickly locate the search through vim positive to this line, under the naming scheme: / git: the X- 

# find the phrase, note that 1000 could be another digital 
git: x: 1000: 1000 :: / home / git: / bin / bash 

# instead: 
git: the X-: 1000: 1000 :: / Home / git: / bin / git-shell 

# best not to change, you can copy a line, and then comment out the line, one-line change to retain the original, this is the experience! ! ! 
# Vim shortcuts: Command mode: yy Copy the line, p paste the cursor to the beginning of the line $ 0 to the end of the line x delete a character i enter insert mode 
# modified after saving exit: esc to enter the command mode, type :: wq save! drop out.

Well, this time we do not have to worry about the client through the login shell, only allows the use of git-shell to manage git repository.

If there are other small partners to connect git server, only to turn his public key to authorized_keys can also be added.

 

Guess you like

Origin www.cnblogs.com/yadongliang/p/11130056.html