2017-02-23 70 views
1

我对git相当陌生,除了Windows之外,很少使用任何其他软件进行编程。配置SSH密钥让git在不在Git Bash中时使用

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

但是,我正在使用Sublime Text进行我的开发,并且想要使用npm plugin从编辑器运行npm run deploy。我得到以下错误:

Cloning [email protected]:<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. 

除非我想念我的猜测,看来混帐不知道自动使用SSH密钥,无论在哪里它正在从运行。有没有办法配置这个?

回答

1

确保在您的环境变量定义:

  • 一个PATH包括<git>/bin以及<git>/usr/bin(与<git>latest Git For Windows的安装路径)
    usr/bin不包括ssh.exe);
  • 一个HOME环境变量设置为%USERPROFILE%

确保您看到dir %HOME%\.ssh

公钥/私钥然后从会话启动SublimeText。

+0

这大多解决了我的问题。为了使'ssh-add'工作,需要设置两个环境变量集,这些变量集在运行'ssh-agent -s'时返回。我猜想让它在Sublime Text中工作的唯一方法是编写一个脚本,它在打开Sublime Text之前从ssh-agent中获取这两个值并在其上运行“setx”。有没有更好的办法? – dfoverdx

+1

@dfoverdx不是我所知道的(如https://github.com/kemayo/sublime-text-git/issues/178或http://stackoverflow.com/q/36338537/6309所示)。但是,您是否需要带密码的私钥? – VonC

+0

我还没有意识到无密码键不需要'ssh-agent'和'ssl-add'。谢谢你的帮助! – dfoverdx