Git server simple Setup 1. Generate a public key. Any engineer who needs to use the git server must generate an ssh public key. You can use ssh-keygen to generate www.2cto.com ~ /. Ssh $ ssh-keygenGenerating public/private rsa key pair. enter file in which to save the key (/home/shiz.pdf /. ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in/home/shiz.pdf /. ssh/id_rsa.Your public key has been saved in/home/shiz.pdf /. ssh/id_rsa.pub.The key fingerprint is: a8: 19: 49: f4: e6: e8: 4f: 8f: 3e: 47: c9: 19: 4c: 09: ee: 7f shizmart @ sz-Your topthe key's randomart image is: first, you will be asked to enter the location where you want to save the public key, press enter directly, and then you will be prompted to repeat the password twice,
If you do not want to use the public key again, enter the password and press Enter. The. ssh directory under the home Directory
Generate two files: id_rsa (Private Key) and id_rsa.pub (Public Key ). Www.2cto.com sends the generated public key id_rsa.pub to the git repository administrator. 2. Set up the server (1) it is best to create a git group on the server side, and then add another git user to the group. Sudo adduser gitsu gitcd ~ Mkdir. ssh creates a. ssh directory for the git user and adds the developer's SSH Public Key to the authorized_keys of the git user.
In this file. There are two developers, zhangsan and lisi. Www.2cto.com cat/tmp/id_rsa_zhangsan.pub> ~ /. Ssh/authorized_keyscat/tmp/id_rsa_lisi.pub> ~ /. Ssh/authorized_keys create an empty repository cd workmkdir project. gitcd project. gitgit -- use bare init -- bare will initialize a repository without any working directory and will not see the source code of the project. To prevent developers from entering IP addresses every time they clone code, you can use DNS. The specific operation is as follows: add the following line 192.168.1.100 gitserver (2) To sudo vim/etc/hosts. If there is no warehouse, you must first create a warehouse. To create a repository, run the following command in the directory. Cd my_projectgit initgit add. (add all files to the repository for management) git commit-m "initial commit" git remote add origin git @ gitserver:/home/git/work/project. git (I .e.: git@192.168.1.100:/home/git/work/project. git) git push origin master if there is a local repository, but you want to push the code to our new server, you can directly use the following command to create a new master branch git checkout-B master xxxxxgit push origin master, which can work on a simple server, other developers can develop code directly from the server.
Www.2cto.com to protect the git server and restrict developers from logging on to the server, the following measures can be taken. Sudo vim/etc/passwd finds the git: x: 1001: 1001:,:/home/git: class at the end of the file: /bin/bash: Change/bin/bash/to/user/bin/git-shell. Now developers can only push and obtain code through SSH and cannot log on to the ssh server. 3. the problem occurs in the current ssh method using the same method. the cause is that the Agent admitted failure to sign using the key solves the problem and adds the private key using the ssh-add command (according change id_rsa according to the key name of an individual) each developer executes the ssh-add id_rsa command.