首先确保自己已经安装了git,打开终端,运行:
查看当前git版本,如果没有安装运行:
sudo npm install git -g
进行git的安装。
运行如下命令对git用户的用户名和邮箱进行配置。
之后再进行上传发现问题已经解决。
1. linux和windows端分别安装git,其中linux中可以用yum安装
[root@node0~]#yum install git
git的默认安装路径在/usr/libexec/git-core
[root@node0 git-core]#cd /usr/libexec/git-core
[root@node0 git-core]#git --version
git version 1.7.1
2.设置linux端git的用户名和密码
[root@node0 git-core]# groupadd git
[root@node0 git-core]# useradd wang -g git
[root@node0 git-core]# passwd wang
New password:
[root@node0 ~]# mkdir -p /mnt/gitrep/wjf
[root@node0 ~]# cd /mnt/gitrep/wjf/
[root@node0 wjf]# git init
Initialized empty Git repository in /mnt/gitrep/wjf/.git/
把仓库所属用户改为wang(git的用户名)
[root@node0 wjf]# chown -R wang:git .git/
注:chown将指定文件的拥有者改为指定的用户或组 -R处理指定目录以及其子目录下的所有文件
4.在windows客户端克隆仓库
$ git clone wang@192.168.111.60:/mnt/gitrep/wjf/.git
Cloning into 'wjf'...
The authenticity of host '192.168.111.60 (192.168.111.60)' can't be established.
RSA key fingerprint is SHA256:MgWCWF************************1m2tI.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.111.60' (RSA) to the list of known hosts.
wang@192.168.111.60's password:
第一次连接远程仓库,出现黑体部分,这是因为Git使用SSH连接,而SSH连接在第一次验证GitHub服务器的Key时,需要你确认GitHub的Key的指纹信息是否真的来自GitHub的服务器,键入yes,然后输入远程仓库的密码就可以了。
5.实际中也通常通过设置公钥的方式来连接远程仓库,这样就不用每次连接都需要密码了。
设置公钥:
1.在windows客户端的gitbash中生成用户私钥和公钥
$ ssh-keygen -t rsa -C "emailname@email.com"
在c盘用户路径下的/.ssh文件夹下会生成私钥id_rsa和公钥id_rsa.pub
2.linux端
首先 Git服务器打开RSA认证,即,修改/etc/ssh/sshd_config,将其中的以下三项打开
RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
然后,将客户端生成的公钥给到服务器端
即,将公钥给到 home/wang(git的用户名)/.ssh/authorized_keys
[root@node0 ~]# cd /home/wang
[root@node0 wang]# mkdir .ssh
[root@node0 wang]# chmod 777 .ssh
[root@node0 wang]# touch .ssh/authorized_keys
在windows客户端的gitbash中 执行:
$ ssh wang@192.168.111.60 'cat >>.ssh/authorized_keys' <~/.ssh/id_rsa.pub
然后在linux端:
[root@node0 wang]# chmod 600 .ssh/authorized_keys
[root@node0 wang]# chmod 700 .ssh
[root@node0 wang]# chown wang:git .ssh
[root@node0 wang]# chown wang:git .ssh/authorized_keys
至此,以后再连接远程仓库就不需要密码了。
若仍需要密码,可以查看ssh连接日志/var/log/secure:
常见连接失败原因:Authentication refused: bad ownership or modes for directory /home/wang/.ssh
这时需要检查该目录的所属用户和读写权限等级是否符合要求。公钥以及.ssh文件的权限应该属于git的用户和用户组,读写权限等级.ssh 700,authorized_keys 600.
1、环境准备服务器:CentOS 7.3 + git (1.8.3.1)
客户端:win10 + git (2.17.0.windows.1)
2、服务器安装git
yum install -y git
3、创建git用户,管理 git服务
[root@localhost home]# useradd git
[root@localhost home]# passwd git
4、服务器创建git 仓库
设置/home/git/repository-git 为git 服务器仓库,然后把 git 仓库的 owner 修改为 git 用户。
复制代码
[root@localhost git]# mkdir repository-git
[root@localhost git]# git init --bare repository-git/
Initialized empty Git repository in /home/git/repository-gt/
[root@localhost git]# chown -R git:git repository-git/
5、客户端安装git
下载 Git for Windows,地址:https://git-for-windows.github.io/
安装完之后,可以使用 Git Bash 作为命令行客户端。
5.1、选择一个目录 F:\project\sell 作为本地仓库,右键进入Git Bash 命令行模式
初始化本地仓库:git init
5.2、尝试克隆一个服务器的空仓库到本地仓库
git clone git@192.168.116.129:/home/git/repository-gt
第一次连接到目标 Git 服务器时会得到一个提示:
The authenticity of host '192.168.116.129(192.168.116.129)' can't be established.
RSA key fingerprint is SHA256:Ve6WV/SCA059EqoUOzbFoZdfmMh3B259nigfmvdadqQ.
Are you sure you want to continue connecting (yes/no)?
选择 yes:
Warning: Permanently added '192.168.116.129' (RSA) to the list of known hosts.
此时 C:\Users\用户名\.ssh 下会多出一个文件 known_hosts,以后在这台电脑上再次连接目标 Git 服务器时不会再提示上面的语句。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)