升木 发表于 2018-9-16 11:03:23

window10系统电脑上安装putty实现免秘钥提交代码到git远程版本库

  说明:以前研发一直是通过输入密码来提交代码到git远程版本库,每次提交代码都得输入服务器的密码,太繁琐,于是研究了下在windows端进行免秘钥来提交代码。

一、pc端安装客户端软件环境说明
  首先要在windows电脑端安装git-bash,TortoiseGit-1.8.8.0-64bit.msi,以及putty这个3个客户端软件。
  这个3个软件的作用说明:
  1.1git-bash客户端软件
  其实就是git在windows端的命令行操作工具,和在linux端git的事一样的功能,都是要通过命令来clone,commit,update代码的。同时git-bash客户端在此处的功能主要是通过登录git-bash来生成windows电脑的公钥和私钥。C:\Users\j.ssh\user001.pub,C:\Users\j.ssh\user001.rsa。然后将生成的windows公钥文件user001.pub上传到git的账户管理机manage上(此机器为linux机器centos6.8的系统)的/root/gitolite-admin/keydir/这个目录下,然后通过git将此user001.pub公钥提交到git的版本库里面。
  1.2.putty客户端软件
  通过putty加载git-bash在windows端的生成的私钥id.rsa文件再来生成id.rsa.ppk文件。这样每次提交代码时,直接加载这个windows端私钥的ppk文件,可以不用输入密码直接提交代码到远程版本库
  1.3TortoiseGit-1.8.8.0-64bit.msi客户端软件
  TortoiseGit软件其实就是git在windows端的桌面版的可视化操作工具,支持汉化版,可以通过TortoiseGit进行各种提交代码。当然通过TortoiseGit在提交代码时可以选择加载putty生成的ppk后缀的私钥文件,来实现免输入密码来提交代码,极大的提高了工作效率

二、客户端软件安装配置说明

2.1git-bash客户端软件安装配置使用

a、安装过程参考此文档:
  官网:https://git-for-windows.github.io/
  https://blog.csdn.net/zzfenglin/article/details/53147604

b、配置使用:
  配置在windows端登录git-bash进行配置环境
  

Administrator@XB-20160409ISPJ MINGW64 ~/Desktop  
$ git config --global user.name "wujianwei"
  

  
Administrator@XB-20160409ISPJ MINGW64 ~/Desktop
  
$ git config --global user.email "3056977536@qq.com"
  

  
Administrator@XB-20160409ISPJ MINGW64 ~/Desktop
  
$ git config --global color.ui true
  

  查看配置列表:
  

Administrator@XB-20160409ISPJ MINGW64 ~/Desktop  
$ git config --list
  
core.symlinks=false
  
core.autocrlf=true
  
core.fscache=true
  
color.diff=auto
  
color.status=auto
  
color.branch=auto
  
color.interactive=true
  
help.format=html
  
rebase.autosquash=true
  
http.sslcainfo=C:/Program Files/Git/mingw64/ssl/certs/ca-bundle.crt
  
diff.astextplain.textconv=astextplain
  
filter.lfs.clean=git-lfs clean -- %f
  
filter.lfs.smudge=git-lfs smudge -- %f
  
filter.lfs.required=true
  
filter.lfs.process=git-lfs filter-process
  
credential.helper=manager
  
user.name=wujianwei
  
user.email=3056977536@qq.com
  
color.ui=true
  

  生成密钥文件:
  

ssh-keygen.exe -t rsa -f /c/Users/Administrator/.ssh/user001  
Generating public/private rsa key pair.
  
Created directory '/c/Users/Administrator/.ssh'.
  
Enter passphrase (empty for no passphrase):
  
Enter same passphrase again:

  
Your>  
Your public key has been saved in /c/Users/Administrator/.ssh/test1.pub.
  
The key fingerprint is:
  
SHA256:EWr9I74XSCIgrJK4I4wYIE3H4hZLHa+UpUrkwsfLkNk Administrator@XB-20160409ISPJ
  
The key's randomart image is:
  
+-------+
  
|.oooo.. .      |
  
|=+@.o= o .       |
  
|*XoE+ + o      |
  
|*oBooo. .o       |
  
|=+.o.. oS.o      |
  
|*.   .....   |
  
|..      ..   |
  
|         ..      |
  
|      ..       |
  
+---------+
  
Administrator@XB-20160409ISPJ MINGW64 ~/Desktop
  
$ cd/c/Users/Administrator/.ssh
  
Administrator@XB-20160409ISPJ MINGW64 ~/.ssh
  
$ ls
  
user001user001.pub
  

  拷贝windows端公钥user001.pub到git账户管理机器10.0.0.56上的目录
  提示报错:
  

#git clone git-server:gitolite-admin  
Initialized empty Git repository in /root/gitolite-admin/.git/
  
Bad owner or permissions on /root/.ssh/config
  
fatal: The remote end hung up unexpectedly
  

  权限不对,一下给600权限解决问题
  

# ll /root/.ssh/config  
-rw-rw-r-- 1 root root 99 Mar 29 11:28 /root/.ssh/config
  
# chmod 600 /root/.ssh/config
  
#git clone git-server:gitolite-admin
  
Initialized empty Git repository in /root/gitolite-admin/.git/
  
Warning: Permanently added '221.195.1.233' (RSA) to the list of known hosts.
  
remote: Counting objects: 6, done.
  
remote: Compressing objects: 100% (4/4), done.
  
remote: Total 6 (delta 0), reused 0 (delta 0)
  
Receiving objects: 100% (6/6), done.
  
# ll gitolite-admin/
  
total 8
  
drwxrwxr-x 2 root root 4096 Mar 29 12:00 conf
  
drwxrwxr-x 2 root root 4096 Mar 29 12:00 keydir
  

  # cd gitolite-admin/keydir/
  # rz
  git-admin.pub user001.pub(user001.pubwindows上git-bash工具生成的公钥文件)
  # git add keydir/user001.pub
  # git push keydir/user001.pub
  此时会在git-server版本仓库机器上的的秘钥文件中增加以下内容
  $ cat .ssh/authorized_keys
  

# gitolite start  
command="/home/git/bin/gitolite-shell user001",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-rsa AAdgj35zaC1yc2EAAAADAQABAAABAQC7GXe0BlOVPq6/WoC/UKhz5i2wBKWkvdZKWiidvo51LmYnFSAKMslKHFXLK9mLqVe0f9ES/hNGkHwroCxlMK1GRHff2t/q5VWAuvoKPskB7s7ISoDt4giANdd/GSDLh7Ih1kyGW6qR47z/M+RoMaDoKrUpduW63L1WuNv6mwPcvzCBYMkK2EDnXnoYUtd/pRm1cLzU6CIoPO8UEwnxbQ/+y6NDoOSChsVjpEIq0u/+rNO/nbUHdKjRMpGpFgeIsdk4ynNYo4/a03LE1wEweet2SDWWWWFEwSwa/t/DGzp39z0Y8/w0AvhRs4HxxPwU4E9Lg331xrlBxv5sXYNO5j j@DESKTOP-MKKM55A
  
# gitolite end
  

  windows端git-bash生成的公钥文件,在服务器上配制到此完成

2.2、putty软件的安装配制使用

a.官网下载地址:
  https://www.chiark.greenend.org.uk/~sgtatham/putty/

b.使用介绍:
  通过putty加载windows端的私钥user001.rsa文件来生成user001.rsa.ppk文件






  到此秘钥生成完成

2.3安装TortoiseGit

a、安装过程:
  安装参考文档:
  官网下载地址:https://tortoisegit.org/download/
  安装参考资料:http://www.iyunv.net/article/55440.htm
  git客户端软件TortoiseGit-1.8.8.0-64bit.msi 下载安装
  官网下载地址:https://tortoisegit.org/download/
  汉化本语言包下载:
  http://jingyan.baidu.com/article/a501d80c292d91ec630f5e3e.html

b、配制使用介绍
  首先在git账户管理机器manage上配制新的版本库test003,并且上传user001.pub,然后提交到git远程仓库
  

# tail -2 /root/gitolite-admin/conf/gitolite.conf  
repo test003
  RW+   =   user001 git-admin
  
# cd /root/gitolite-admin/
  
# ls
  
confkeydir
  
# cd keydir/
  
# rz 上传windows上生成的公钥user001.pub
  
# ls
  
git-admin.pubuser001.pub
  

  
#git add./conf/gitolite.conf
  
#git add ./keydir/user001.pub
  
# git status
  

#On branch master  
#Changes to be committed:
  
#(use "git reset HEAD ..." to unstage)
  
#
  
#   modified:   conf/gitolite.conf
  
#   modified:   conf/keydir
  
#
  
# git commit -m "the test user001"
  
the test user001
  Committer: root
  
Your name and email address were configured automatically based
  
on your username and hostname. Please check that they are accurate.
  
You can suppress this message by setting them explicitly:
  

  git config --global user.name "Your Name"
  git config --global user.email you@example.com
  


  
If the>  

  git commit --amend --author='Your Name '
  

  1 files changed, 2 insertions(+), 0 deletions(-)
  
# git push
  
Counting objects: 7, done.
  
Delta compression using up to 16 threads.
  
Compressing objects: 100% (3/3), done.
  
Writing objects: 100% (4/4), 360 bytes, done.
  
Total 4 (delta 1), reused 0 (delta 0)
  
remote: Initialized empty Git repository in /home/zydrgit/repositories/test003.git/
  
To git-server:gitolite-admin
  65e5385..d349781master -> master
  

  #
  在远程版本库上新生成test003.git版本库
  

$ ls  
gitolite-admin.gittest001.gittest003.gittesting.git
  

c、在windows上使用TortoiseGit来clone和提交代码


  提交代码到远程版本库:



  到此处所有的配制和演示全部完成


页: [1]
查看完整版本: window10系统电脑上安装putty实现免秘钥提交代码到git远程版本库