• 下载Plink安装包:

https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

  • 下载Git for Windows安装包:

https://git-scm.com/download/win

  • 将Plink安装路径添加到系统环境变量,在CMD中测试:
C:\Users\user>plink --version  
plink: Release 0.69  
Build platform: 64-bit Windows  
Compiler: Visual Studio 2015 / MSVC++ 14.0 (_MSC_VER=1900)  
Source commit: b1829b81b5c0d12dcc91f6b50b0b4d83c3df6a8e  
  • 使用puttygen.exe创建RSA密钥,将公钥删除开头两行与最后一行,并在开头添加ssh-rsa空格,然后复制粘贴到GitHub:
---- BEGIN SSH2 PUBLIC KEY ----
Comment: "rsa-key-20200520"

---- END SSH2 PUBLIC KEY ----
  • 打开管理员权限的Powershell,执行以下命令,使git默认使用plink:
[Environment]::SetEnvironmentVariable("GIT_SSH", "C:\--Your-PUTTY-Install-Path\plink.exe", "User")
  • 打开pageant.exe,导入刚才使用puttygen.exe生成的密钥,然后在cmd中登录GitHub测试:
C:\Users\user>plink git@github.com  
Using username "git".  
Server refused to allocate pty  
Hi user! You've successfully authenticated, but GitHub does not provide shell access.  
  • 添加Emacs配置
(require 'tramp)
(setq tramp-shell-prompt-pattern "^[ $]+")
(setq tramp-default-method "plink")
!!--If-you-use-spacemacs--!!
(setq tramp-ssh-controlmaster-options
    "-o ControlMaster=auto -o ControlPath='tramp.%%C' -o ControlPersist=no")