Windows下搭建git服务器

一、服务器端

安装Git

安装Copssh

说明

安装路径中不要出现空格,以免不必要的麻烦。比较安装到X:\Program Files\下的话,在路径中需要写为/X/Program\ Files/

我最终安装目录结构如下,仅供参考。

D
  |-Git
      |-Copssh    SSH目录
      |-Git       Git目录
  |-Kingsun       仓库目录

配置环境变量

右键单击“计算机”->选择“属性”->选择“高级系统设置”->在弹出的“系统属性”窗口中选择“高级”选择卡->单击下方的“环境变量”按钮->在弹出的“环境变量”窗口中找到“系统变量”->双击“Path”弹出“编辑系统变量”。在“变量值”中加入安装Git的如下路径:

D:\Git\Git\bin\
D:\Git\Git\mingw32\libexec\git-core\

注意路径之间以;号分隔。

配置Copssh

添加用户

测试ssh连接

$ ssh [email protected]

可能出现的错误

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:uzpEC1KwT+29rcJaLqzfEiBXbpRWF1LYPHAmyFaYZ24.
Please contact your system administrator.
Add correct host key in /c/Users/Administrator/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /c/Users/Administrator/.ssh/known_hosts:1
ECDSA host key for 196.1.1.12 has changed and you have requested strict checking.
Host key verification failed.

解决办法

删除C:\Users\Administrator\.ssh下的known_hosts文件后重新尝试。

如里出现以下提示:

$ ssh [email protected]
The authenticity of host '196.1.1.12 (196.1.1.12)' can't be established.
ECDSA key fingerprint is SHA256:uzpEC1KwT+29rcJaLqzfEiBXbpRWF1LYPHAmyFaYZ24.
Are you sure you want to continue connecting (yes/no)? 

输入yes继续,

Warning: Permanently added '196.1.1.12' (ECDSA) to the list of known hosts.
[email protected]'s password:

接下来输入密码后回车,看到git@YFSERVER01 ~说明连接成功。可输入$ exit退出连接。

初始化仓库

二、客户端

安装Git

克隆远程仓库

密码方式

输入$ git clone ssh://[email protected]/kingsun/test.git并回车

Cloning into 'test'...
[email protected]'s password:

输入密码

remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
Checking connectivity... done.

如果看到上述信息说明克隆成功。

常见错误

*错误1*

fatal: 'xxx' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

*错误2*

fatal: repository '[email protected]/kingsun/test.git' does not exist

*解决办法*

写法很重要,仔细检查仓库路径是否正确。

$ git clone ssh://[email protected]/kingsun/test.git 正确
$ git clone ssh://[email protected]/d/kingsun/test.git 错误1
$ git clone [email protected]:22/kingsun/test.git 错误1
$ git clone [email protected]:kingsun/test.git 错误1
$ git clone [email protected]/kingsun/test.git 错误2

*错误3*

bash: git-upload-pack: command not found
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

*解决办法*

检查第3步中的环境变量是否配置正确,配置正确后重新启动Openssh SSHD服务。然后再次尝试重新克隆。

push到远程服务器

$ git push origin master

输入密码

可能出现以错误

[email protected]'s password:

Counting objects: 3, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 261 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 t
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing int
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 som
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, se
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To ssh://[email protected]/kingsun/test.git
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://[email protected]/kingsun/test.git'

解法办法

在服务器上执行以下命令:

git config receive.denyCurrentBranch ignore

或在.git/config文件后面添加如下代码:

[receive]

denyCurrentBranch = ignore

公钥方式

上传公钥

修改Copssh配置

测试ssh连接

$ ssh [email protected]

*常见错误*

Permission denied (publickey,keyboard-interactive).

-v参数

$ ssh [email protected] -v

OpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 196.1.1.12 [196.1.1.12] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8
debug1: match: OpenSSH_5.8 pat OpenSSH_5* compat 0x0c000000
debug1: Authenticating to 196.1.1.12:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:uzpEC1KwT+29rcJaLqzfEiBXbpRWF1LYPHAmyFaYZ24
debug1: Host '196.1.1.12' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/Administrator/.ssh/known_hosts:1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Administrator/.ssh/id_rsa
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /c/Users/Administrator/.ssh/id_dsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: No more authentication methods to try.
Permission denied (publickey,keyboard-interactive).

多加几个加-v参数

$ ssh [email protected] -vvv

OpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: ssh_connect: needpriv 0
debug1: Connecting to 196.1.1.12 [196.1.1.12] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Administrator/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8
debug1: match: OpenSSH_5.8 pat OpenSSH_5* compat 0x0c000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 196.1.1.12:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: [email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],ssh-ed25519,ssh-rsa
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected],arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1,[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:uzpEC1KwT+29rcJaLqzfEiBXbpRWF1LYPHAmyFaYZ24
debug1: Host '196.1.1.12' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/Administrator/.ssh/known_hosts:1
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /c/Users/Administrator/.ssh/id_rsa (0x2005f150),
debug2: key: /c/Users/Administrator/.ssh/id_dsa (0x0),
debug2: key: /c/Users/Administrator/.ssh/id_ecdsa (0x0),
debug2: key: /c/Users/Administrator/.ssh/id_ed25519 (0x0),
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /c/Users/Administrator/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,keyboard-interactive
debug1: Trying private key: /c/Users/Administrator/.ssh/id_dsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519
debug2: we did not send a packet, disable method
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug1: Authentications that can continue: publickey,keyboard-interactive
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey,keyboard-interactive).

*解决办法*

参考windows 下搭建git服务器,及问题处理。但仍然未解决,待续。。。

你可能感兴趣的:(版本控制)