[root@node1 ~]# useradd -d /opt/user1 user1
[root@node1 ~]# echo "user1" |passwd --stdin user1
更改用户 user1 的密码 。
passwd: 所有的身份验证令牌已经成功更新。
[root@node1 ~]# useradd -d /opt/user2 user2
[root@node1 ~]# echo "user2" |passwd --stdin user2
更改用户 user2 的密码 。
passwd: 所有的身份验证令牌已经成功更新。
[root@node1 ~]#
[root@node1 ~]# su - user1
[user1@node1 ~]$ ssh-keygen -t rsa
[root@node1 ~]# su - user2
[user1@node1 ~]$ ssh-keygen -t rsa
分别将user1、user2 用户的公钥新增git仓库服务器侧的
[user2@node1 .ssh]$ pwd
/opt/user2/.ssh
[user2@node1 .ssh]$ ll
总用量 8
-rw-------. 1 user2 user2 1671 9月 22 17:18 id_rsa
-rw-r--r--. 1 user2 user2 404 9月 22 17:18 id_rsa.pub
[user2@node1 .ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp0Im8iL7UR2b0PWrJ98YY/nqvjnuYWNc2F52SYn1/WA8rwGBWW0WBmKMoyW8YfSpCVk7QbyhX48Y3KF/Gf16CWRMm8xuyA+S5Seq3ZGnLbbVhb0OMO8VDAldovnIuPdI6005+ux/WbG1FKr3WxGs5k92ZO9hbXxpcVAwpvHY47t1v2LH5fW2jThypWMolUdp9TaNy7FkD2zaUNhbdqM1w67OSydiHAMfj183sEso9TykiXJvwlJeLdUMFywPTwfVqu2rxV0lY68B2mwr1pl5mcGPA4/0ruX8vSFsFLev8+yi7LjccChAu/suPIFGLqRXrkW8ymsN/l3CkldnS9Y0BQ== user2@node1.lansgg.com
[user2@node1 .ssh]$
git 仓库服务侧
[gitServer@Linuxidc ~]$ mkdir .ssh && chmod 700 .ssh
[gitServer@Linuxidc ~]$ touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys
[gitServer@Linuxidc ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA1pII1U64N/wl1OXotWdcU8d8+ad0q6tkqdBgXLcR5zqXIq9PPe1NeLJ5HS9UIvZeN/LEyXGYh+fyg8tFQ+2PN3CmxnVwwcciyl1AKAgTeKUdleh8qcXPZkI0YZBpgTbuYWYHNjA6Qd9cvJSdKe9cVvwsv7N1z17Mx1uIfNSuSZ9e4XqUsJksBAzAYEGar4S13+Y/il7lquwkrdVBiWfWHmf/WoeY2RnzNBe9YtPVFUPL8HEoYyYaU+YXXMZKOZ8JwuLu1CPDJHTquSTyqdEwmgJWDdoiipgtyVOEVGZC0CqV16M2YpVqw26rrZ+nXUQYEnTrWyIiqt8/xvzmeDIf0Q== user1@node1.lansgg.com
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAp0Im8iL7UR2b0PWrJ98YY/nqvjnuYWNc2F52SYn1/WA8rwGBWW0WBmKMoyW8YfSpCVk7QbyhX48Y3KF/Gf16CWRMm8xuyA+S5Seq3ZGnLbbVhb0OMO8VDAldovnIuPdI6005+ux/WbG1FKr3WxGs5k92ZO9hbXxpcVAwpvHY47t1v2LH5fW2jThypWMolUdp9TaNy7FkD2zaUNhbdqM1w67OSydiHAMfj183sEso9TykiXJvwlJeLdUMFywPTwfVqu2rxV0lY68B2mwr1pl5mcGPA4/0ruX8vSFsFLev8+yi7LjccChAu/suPIFGLqRXrkW8ymsN/l3CkldnS9Y0BQ== user2@node1.lansgg.com
[gitServer@Linuxidc ~]$
客户测试机 无需用户名、密码
[user1@node1 ~]$ git clone gitServer@192.168.100.128:/opt/gitServer/TestProject.git
Initialized empty Git repository in /opt/user1/TestProject/.git/
The authenticity of host '192.168.100.128 (192.168.100.128)' can't be established.
RSA key fingerprint is 9f:32:3a:b0:db:03:b6:c8:fc:a0:47:6c:e5:d1:b0:6a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.100.128' (RSA) to the list of known hosts.
remote: Counting objects: 9, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 9 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (9/9), done.
[user1@node1 ~]$
如果提交过程:提示如下错误
Counting objects: 3, done.
Writing objects: 100% (3/3), 247 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
试着将如下配置新增到
[git@JumpServer1 pl.git]$ cat .git/config
[receive]
denyCurrentBranch = ignore
再次提交
GitHub 教程系列文章: