Windows下搭建git服务器

来源:互联网 发布:eos utility mac 编辑:程序博客网 时间:2024/05/16 19:47

一、服务器端

安装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 git@196.1.1.12

可能出现的错误

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@    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 isSHA256: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:1ECDSA 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 git@196.1.1.12The 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.git@196.1.1.12's password:

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

初始化仓库

二、客户端

安装Git

克隆远程仓库

密码方式

输入$ git clone ssh://git@196.1.1.12/kingsun/test.git并回车

Cloning into 'test'...git@196.1.1.12'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 repositoryfatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.

*错误2*

fatal: repository 'git@196.1.1.12/kingsun/test.git' does not exist

*解决办法*

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

$ git clone ssh://git@196.1.1.12/kingsun/test.git 正确$ git clone ssh://git@196.1.1.12/d/kingsun/test.git 错误1$ git clone git@196.1.1.12:22/kingsun/test.git 错误1$ git clone git@196.1.1.12:kingsun/test.git 错误1$ git clone git@196.1.1.12/kingsun/test.git 错误2

*错误3*

bash: git-upload-pack: command not foundfatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.

*解决办法*

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

push到远程服务器

$ git push origin master

输入密码

可能出现以错误

git@196.1.1.12'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/masterremote: error: By default, updating the current branch in a non-bare repositoryremote: error: is denied, because it will make the index and work tree inconsistentremote: error: with what you pushed, and will require 'git reset --hard' to matchremote: error: the work tree to HEAD.remote: error:remote: error: You can set 'receive.denyCurrentBranch' configuration variable tremote: error: 'ignore' or 'warn' in the remote repository to allow pushing intremote: error: its current branch; however, this is not recommended unless youremote: error: arranged to update its work tree to match what you pushed in somremote: error: other way.remote: error:remote: error: To squelch this message and still keep the default behaviour, seremote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.To ssh://git@196.1.1.12/kingsun/test.git ! [remote rejected] master -> master (branch is currently checked out)error: failed to push some refs to 'ssh://git@196.1.1.12/kingsun/test.git'

解法办法

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

git config receive.denyCurrentBranch ignore

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

[receive]denyCurrentBranch = ignore

公钥方式

上传公钥

修改Copssh配置

测试ssh连接

$ ssh git@196.1.1.12

*常见错误*

Permission denied (publickey,keyboard-interactive).

-v参数

$ ssh git@196.1.1.12 -vOpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015debug1: Reading configuration data /etc/ssh/ssh_configdebug1: 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 1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_7.1debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8debug1: match: OpenSSH_5.8 pat OpenSSH_5* compat 0x0c000000debug1: Authenticating to 196.1.1.12:22 as 'git'debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug1: kex: server->client aes128-ctr umac-64@openssh.com nonedebug1: kex: client->server aes128-ctr umac-64@openssh.com nonedebug1: sending SSH2_MSG_KEX_ECDH_INITdebug1: expecting SSH2_MSG_KEX_ECDH_REPLYdebug1: Server host key: ecdsa-sha2-nistp256 SHA256:uzpEC1KwT+29rcJaLqzfEiBXbpRWF1LYPHAmyFaYZ24debug1: Host '196.1.1.12' is known and matches the ECDSA host key.debug1: Found key in /c/Users/Administrator/.ssh/known_hosts:1debug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug1: SSH2_MSG_NEWKEYS receiveddebug1: SSH2_MSG_SERVICE_REQUEST sentdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug1: Authentications that can continue: publickey,keyboard-interactivedebug1: Next authentication method: publickeydebug1: Offering RSA public key: /c/Users/Administrator/.ssh/id_rsadebug1: Authentications that can continue: publickey,keyboard-interactivedebug1: Trying private key: /c/Users/Administrator/.ssh/id_dsadebug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsadebug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519debug1: Next authentication method: keyboard-interactivedebug1: Authentications that can continue: publickey,keyboard-interactivedebug1: No more authentication methods to try.Permission denied (publickey,keyboard-interactive).

多加几个加-v参数

$ ssh git@196.1.1.12 -vvvOpenSSH_7.1p2, OpenSSL 1.0.2d 9 Jul 2015debug1: Reading configuration data /etc/ssh/ssh_configdebug2: ssh_connect: needpriv 0debug1: 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 1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_rsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_dsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_dsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ecdsa type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ecdsa-cert type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ed25519 type -1debug1: key_load_public: No such file or directorydebug1: identity file /c/Users/Administrator/.ssh/id_ed25519-cert type -1debug1: Enabling compatibility mode for protocol 2.0debug1: Local version string SSH-2.0-OpenSSH_7.1debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8debug1: match: OpenSSH_5.8 pat OpenSSH_5* compat 0x0c000000debug2: fd 3 setting O_NONBLOCKdebug1: Authenticating to 196.1.1.12:22 as 'git'debug1: SSH2_MSG_KEXINIT sentdebug1: SSH2_MSG_KEXINIT receiveddebug2: kex_parse_kexinit: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1debug2: kex_parse_kexinit: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ssh-ed25519,ssh-rsadebug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1,hmac-md5-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: none,zlib@openssh.com,zlibdebug2: kex_parse_kexinit: none,zlib@openssh.com,zlibdebug2: kex_parse_kexinit:debug2: kex_parse_kexinit:debug2: first_kex_follows 0debug2: reserved 0debug2: 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-sha1debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.sedebug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96debug2: kex_parse_kexinit: none,zlib@openssh.comdebug2: kex_parse_kexinit: none,zlib@openssh.comdebug2: kex_parse_kexinit:debug2: kex_parse_kexinit:debug2: first_kex_follows 0debug2: reserved 0debug1: kex: server->client aes128-ctr umac-64@openssh.com nonedebug1: kex: client->server aes128-ctr umac-64@openssh.com nonedebug1: sending SSH2_MSG_KEX_ECDH_INITdebug1: expecting SSH2_MSG_KEX_ECDH_REPLYdebug1: Server host key: ecdsa-sha2-nistp256 SHA256:uzpEC1KwT+29rcJaLqzfEiBXbpRWF1LYPHAmyFaYZ24debug1: Host '196.1.1.12' is known and matches the ECDSA host key.debug1: Found key in /c/Users/Administrator/.ssh/known_hosts:1debug2: set_newkeys: mode 1debug1: SSH2_MSG_NEWKEYS sentdebug1: expecting SSH2_MSG_NEWKEYSdebug2: set_newkeys: mode 0debug1: SSH2_MSG_NEWKEYS receiveddebug1: SSH2_MSG_SERVICE_REQUEST sentdebug2: service_accept: ssh-userauthdebug1: SSH2_MSG_SERVICE_ACCEPT receiveddebug2: 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-interactivedebug1: Next authentication method: publickeydebug1: Offering RSA public key: /c/Users/Administrator/.ssh/id_rsadebug2: we sent a publickey packet, wait for replydebug1: Authentications that can continue: publickey,keyboard-interactivedebug1: Trying private key: /c/Users/Administrator/.ssh/id_dsadebug1: Trying private key: /c/Users/Administrator/.ssh/id_ecdsadebug1: Trying private key: /c/Users/Administrator/.ssh/id_ed25519debug2: we did not send a packet, disable methoddebug1: Next authentication method: keyboard-interactivedebug2: userauth_kbdintdebug2: we sent a keyboard-interactive packet, wait for replydebug1: Authentications that can continue: publickey,keyboard-interactivedebug2: we did not send a packet, disable methoddebug1: No more authentication methods to try.Permission denied (publickey,keyboard-interactive).

*解决办法*

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

1 0
原创粉丝点击