1、分别在linux(服务器)上安装git、和openssh服务,
在windows(客户机)上安装cygwin,模拟linux环境以及安装windows git客户端。
2、windows的cygwin环境安装SSH服务:
运行 C:\cygwin64\Cygwin.bat
或终端
在窗口中输入
ssh-host-config
*** Query: Should privilege separation be used? <yes/no>: yes
*** Query: New local account 'sshd'? <yes/no>: yes
*** Query: Do you want to install sshd as a service?
*** Query: <Say "no" if it is already installed as a service> <yes/no>: yes
*** Query: Enter the value of CYGWIN for the deamon: [] binmode ntsec
*** Query: Do you want to use a different name? (yes/no) yes/no
如果用相同的名字 cyg_server,
输入no.
*** Query: Create new privileged user account 'cyg_server'? (yes/no) yes
*** Query: Please enter the password:
*** Query: Renter:
如果选择不同的名字, 输入 yes.
*** Query: Enter the new user name: cyg_server1
*** Query: Reenter: cyg_server1
*** Query: Create new privileged user account 'cyg_server1'? (yes/no) yes
*** Query: Please enter the password:
*** Query: Reenter:
配置相应的密码,输入yes
配置成功,你会看到下面消息:
Host configuration finished. Have fun!
useradd git
passwd git
vi /etc/passwd:
将
git:x:1001:1001:,,,:/home/git:/bin/bash 改成
git:x:1001:1001:,,,:/home/git:/usr/bin/git-shell
git init --bare /home/git/swportal.git
cd /home/git
chown -R git:git swportal.git/
我们 通过命令scp /home/git/.ssh/id_rsa.pub gitServer:/home/git将gitClient_01上生成的公钥拷贝到gitServer上。
在gitServer上我们首先查看/home/git/.ssh目录下是否存在authorized_kesys文件,
如果没有,可以通过touch authorized_keys创建此文件。
Authorized_keys创建完成后,将gitClient_01上拷贝过来的公钥id_rsa.pub的内容追 加到authroized_keys中,注意是追加到此文件中,可以使用命令cat /home/git/id_rsa.pub>>/home/git/.ssh/authorized_keys.\
6、***添加远程git仓库链接并push本地库内容给远程库
git remote add origin2 root@109.110.100.56:/usr/src/git-2.1.2/data/git/swportal.git
git push -u origin master
7、***git远程命令(记得把git push文件所在的文件夹的权限给成全部控制)
git remote
git clone
git fetch
git pull
git push