简体   繁体   English

Windows命令行GIT密码提示

[英]Windows command line GIT password prompt

I have mysysgit and TortoiseGit installed on a Windows PC, which connects to a remote Git repo on a Linux box. 我在Windows PC上安装了mysysgit和TortoiseGit,该PC连接到Linux机器上的远程Git存储库。 I have created ssh keys, and added them to the profile in TortoiseGit. 我已经创建了ssh密钥,并将它们添加到TortoiseGit中的配置文件中。 When I interact with the remote repo in TortoiseGit, it all works fine. 当我在TortoiseGit中与远程仓库交互时,一切正常。 No password prompting. 没有密码提示。 However, when I try to run Git commands from the command line, I get prompted for the SSH password. 但是,当我尝试从命令行运行Git命令时,系统提示输入SSH密码。

What do I need to do so that I'm not prompted for the password from the command line? 我需要怎么做才能不提示我从命令行输入密码?

Make sure your git session references the TortoisePLink.exe (in GIT_SSH environment variable), as described in " Why git can't remember my passphrase under Windows ": 确保您的git会话引用了TortoisePLink.exe (在GIT_SSH环境变量中),如“ 为什么git在Windows下无法记住我的密码短语 ”中所述:

(you might have done the first two steps already) (您可能已经完成了前两个步骤)

  • convert your key for use with TortoiseGit's pageant.exe using TortoiseGit's puttygen.exe . 使用TortoiseGit的puttygen.exe转换您的密钥以用于TortoiseGit的pageant.exe
  • Run TortoiseGit's pageant.exe , open your .ppk file ("Add Key"), and provide your passphrase for your key. 运行TortoiseGit的pageant.exe ,打开您的.ppk文件(“添加密钥”),并提供密钥密码。
  • add the environment variable: 添加环境变量:

     GIT_SSH=C:\\full\\path\\to\\TortoisePlink.exe 

This assumes your TortoiseGit is using TortoisePlink.exe . 假设您的TortoiseGit使用的是TortoisePlink.exe


The OP scott80109 concludes in the comments : OP scott80109 在评论中总结:

msysgit was installed to use Open SSH. 已安装msysgit以使用Open SSH。
I changed it to use plink , and it now works without a prompt 我将其更改为使用plink ,现在无需提示即可使用


Erez A. Korn adds in the comments : Erez A. Korn 在评论中添加:

I prefer to use openssh as it doesn't require me to have my key in an alternative format (ppk). 我更喜欢使用openssh,因为它不需要我将密钥设置为其他格式(ppk)。
I've written a small wrapper to launch the ssh-agent and take care of business and then added it to my Windows Startup. 我编写了一个小的包装程序来启动ssh-agent并处理事务,然后将其添加到Windows Startup中。
You can check the code in erezak/ssh-agent-wrapper-win . 您可以在erezak/ssh-agent-wrapper-win检查代码。

I recommend to use pageant. 我建议使用选美比赛。 read this http://guides.beanstalkapp.com/version-control/git-on-windows.html and add you ssh-key to pageant. 阅读此http://guides.beanstalkapp.com/version-control/git-on-windows.html并将ssh-key添加到选美中。 it affects globally. 它影响全球。

My use case needed multiple github users with passphrase-protected ssh keys. 我的用例需要使用密码保护的ssh密钥的多个github用户。

I sorted my ~.ssh/config file to use different keys for different repo domains, as described here 我整理我的~.ssh/config文件,以用于不同的回购域不同的密钥,如所描述这里

However, I don't want to type my passphrase every time, and I don't want to use ssh-agent. 但是,我不想每次都输入密码,也不想使用ssh-agent。

Here's how I set up Pageant to ask for and remember my passphrase on Windows login: 这是我设置Pageant来询问并记住Windows登录密码的方法:

  • Download the Putty Tools package 下载腻子工具包
  • Win+R to open run dialog Win + R打开运行对话框
  • shell:startup to open the auto start folder in windows explorer shell:startup在Windows资源管理器中打开自动启动文件夹
  • Navigate to your Pageant folder in a separate Explorer window 在单独的资源管理器窗口中导航到Pageant文件夹
  • Right click and drag PAGEANT.EXE to the Startup folder. 右键单击并将PAGEANT.EXE拖到“启动”文件夹中。 Choose Create Shortcut 选择创建快捷方式
  • Right click the shortcut, properties, Shortcut tab 右键单击快捷方式,属性,快捷方式选项卡
  • Find the path to your .ppk encoded keypair 找到您的.ppk编码密钥对的路径
    • generate one with PUTTYGEN.EXE if you need a new one 如果您需要一个新的PUTTYGEN.EXE生成一个
    • convert one with PUTTYGEN.EXE if you have a linux id_rsa file but no .ppk 如果您有linux id_rsa文件但没有.ppk,请使用PUTTYGEN.EXE进行转换
    • win7+ : shift right click your key in Explorer, Copy as path win7 +:在资源管理器中右击您的键, 复制为路径
  • Append the key path to the C:\\whatever\\PAGEANT.EXE line 将密钥路径附加到C:\\ whatever \\ PAGEANT.EXE行
    • eg: "Target: C:\\putty\\PAGEANT.EXE plato_cambrian.ppk plato.ppk " 例如:“目标: C:\\putty\\PAGEANT.EXE plato_cambrian.ppk plato.ppk
    • If your keys aren't adjacent to PAGEANT you can use absolute paths or change "Start in:" which is Pageant's CWD 如果您的密钥与PAGEANT不相邻,则可以使用绝对路径或更改“开始于:”(这是Pageant的CWD)
  • Open the shortcut or reboot, and type your passphrases 打开快捷方式或重新启动,然后输入密码

Also, for anyone on ubuntu/linux mint who ended up here, I documented similar steps here 另外,在Ubuntu / Linux Mint的谁结束了在这里的人,我记录的类似的步骤在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM