【问题标题】:Configuring SSH keys for git to use when not in Git Bash为不在 Git Bash 中的 git 配置 SSH 密钥
【发布时间】:2017-07-13 11:11:30
【问题描述】:

我对 git 还很陌生,除了 Windows 之外很少使用任何东西进行编程。

我使用create-react-app 设置了一个React 应用程序,并使用gh-pages 将其部署到我的github.io 项目页面。我已经在本地机器上设置了一个 SSH 密钥并将其添加到我的 github SSH 密钥中。运行 ssh-agentssh-add 使得在 Git Bash 中的部署变得简单,无需输入用户名和密码。太好了。

但是,我正在使用Sublime Text 进行开发,并希望直接从编辑器中使用npm plugin 运行npm run deploy。我收到以下错误:

Cloning git@github.com:<username>/<repo>.git into node_modules\gh-pages\.cache
Cloning into 'node_modules\gh-pages\.cache'...
Permission denied (publickey).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

除非我猜错了,否则 git 似乎不知道自动使用 SSH 密钥,无论它是从哪里运行的。有没有办法配置这个?

【问题讨论】:

    标签: git github ssh npm sublimetext3


    【解决方案1】:

    确保在你的环境变量中定义:

    • 一个PATH,其中包括&lt;git&gt;/bin&lt;git&gt;/usr/bin&lt;git&gt;latest Git For Windows的安装路径)
      usr/bin 确实包括ssh.exe);
    • HOME 环境变量设置为您的 %USERPROFILE%

    确保您在 dir %HOME%\.ssh 中看到您的公钥/私钥

    然后从该会话中启动 SublimeText。

    【讨论】:

    • 这主要解决了我的问题。为了使ssh-add 工作,需要设置两个环境变量,当ssh-agent -s 运行时返回。我猜想让它在 Sublime Text 中工作的唯一方法是编写一个脚本,从 ssh-agent 中提取这两个值并在打开 Sublime Text 之前在它们上运行setx。有没有更好的办法?
    • @dfoverdx 我不知道(如github.com/kemayo/sublime-text-git/issues/178stackoverflow.com/q/36338537/6309 所示)。但是你需要一个带密码的私钥吗?
    • 我没有意识到无密码密钥不需要ssh-agentssl-add。感谢您的帮助!
    猜你喜欢
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多