如何ubuntu上创建git仓库
服务端
1 2 3 [root@admin ~] ziming@zm -gcp-vm-ubuntu16-tw-8 :~ $ git version git version 2.7 .4
1 2 3 4 5 ziming@zm -gcp-vm-ubuntu16-tw-8 :/home $ sudo useradd git ziming@zm -gcp-vm-ubuntu16-tw-8 :/home $ sudo passwd git Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
创建git仓库,并且将管理者变成新创建的git用户
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 ziming@zm -gcp-vm-ubuntu16-tw-8 :/home $ sudo mkdir -p ./git/rep/gcp.git ziming@zm -gcp-vm-ubuntu16-tw-8 :/home $ ls git jermainenee me ubuntu ziming zimingnee ziming@zm -gcp-vm-ubuntu16-tw-8 :/home $ cd git ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ ls rep ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ cd rep/ ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/rep $ ls gcp.git ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/rep $ git init --bare ./gcp.git /home/git/rep/gcp.git/refs: Permission denied ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/rep $ sudo git init --bare ./gcp.git Initialized empty Git repository in /home/git/rep/gcp.git/ ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/rep $ cd .. ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ ll total 12 drwxr-xr-x 3 root root 4096 Apr 21 19 : 01 ./ drwxr-xr-x 8 root root 4096 Apr 21 19 : 01 ../ drwxr-xr-x 3 root root 4096 Apr 21 19 : 01 rep/ ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ sudo chown -R git: git rep ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ ll total 12 drwxr-xr-x 3 root root 4096 Apr 21 19 : 01 ./ drwxr-xr-x 8 root root 4096 Apr 21 19 : 01 ../ drwxr-xr-x 3 git git 4096 Apr 21 19 : 01 rep/
1 2 3 4 5 6 ziming@zm-gcp-vm-ubuntu16-tw-8:/home/git$ sudo apt-get install openssh-server Reading package lists.. . Done Building dependency tree Reading state information.. . Done openssh-server is already the newest version (1:7.2p2-4ubuntu2.10). 0 upgraded, 0 newly installed, 0 to remove and 13 not upgraded.
客户端
1 2 3 4 5 ziming@Mechrev MINGW64 /d/development/WebStormProjects $ mkdir gcpziming@Mechrev MINGW64 /d/development/WebStormProjects $ cd gcp/
1 2 3 4 5 6 7 $ git clone git@35 .236.130 .209:22 /:/home/git/rep/gcp .gitCloning into 'gcp' ... git@35 .236.130 .209 : Permission denied (publickey). fatal: Could not read from remote repository.Please make sure you have the correct access rights and the repository exists.
解决权限问题创建sshkey
服务端
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ziming@zm -gcp-vm-ubuntu16-tw-8 :/etc/ssh $ sudo sshd_config ziming@zm -gcp-vm-ubuntu16-tw-8 :/etc/ssh $ sudo vim sshd_config PubkeyAuthentication yes RSAAuthentication yes AuthorizedKeysFile .ssh/authorized_keys ziming@zm -gcp-vm-ubuntu16-tw-8 :/etc/ssh $ sudo sshd_config ziming@zm -gcp-vm-ubuntu16-tw-8 :/etc/ssh $ sudo vim sshd_config ziming@zm -gcp-vm-ubuntu16-tw-8 :/etc/ssh $ sudo service sshd restart ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ sudo chown -R git: git .ssh ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git $ ll total 16 drwxr-xr-x 4 root root 4096 Apr 21 19 : 23 ./ drwxr-xr-x 8 root root 4096 Apr 21 19 : 01 ../ drwxr-xr-x 3 git git 4096 Apr 21 19 : 01 rep/ drwxr-xr-x 2 git git 4096 Apr 21 19 : 23 .ssh/
1 2 3 4 5 6 7 8 9 10 ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/ .ssh$ sudo vim authorized_keys ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/ .ssh$ cat authorized_keys sh-rsa ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/ .ssh$ sudo chmod 600 authorized_keys ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/ .ssh$ sudo chmod 700 ../.ssh/ ziming@zm -gcp-vm-ubuntu16-tw-8 :/home/git/ .ssh$
再次拉取即可
在Ubuntu上搭建git服务器
https://blog.csdn.net/baidu_38661691/article/details/88658033