如何在 Windows 上运行 ssh-add?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18683092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run ssh-add on windows?
提问by cqcn1991
I'm following #335 Deploying to a VPS , and near the end of the episode, we need to run ssh-add
to give server access to github repo.
我正在关注#335 Deploying to a VPS,在本集快结束时,我们需要运行ssh-add
以授予服务器访问 github 存储库的权限。
The problem is how do I run it in windows? What need to install?
问题是我如何在 Windows 中运行它?需要安装什么?
I know that to run ssh
to access the remote server, I can use Putty
. But this command needs to run locally, I do know how to use Putty
to do this.
我知道要运行ssh
以访问远程服务器,我可以使用Putty
. 但是这个命令需要在本地运行,我知道如何使用Putty
它。
回答by tamj0rd2
Original answer using git's start-ssh-agent
使用 git 的 start-ssh-agent 的原始答案
Make sure you have Git installed and have git's cmd
folder in your PATH. For example, on my computer the path to git's cmd folder is C:\Program Files\Git\cmd
确保你已经安装了 Git 并且cmd
在你的 PATH 中有 git 的文件夹。例如,在我的电脑上,git 的 cmd 文件夹的路径是C:\Program Files\Git\cmd
Make sure your id_rsa
file is in the folder c:\users\yourusername\.ssh
确保您的id_rsa
文件在文件夹中c:\users\yourusername\.ssh
Restart your command prompt if you haven't already, and then run start-ssh-agent
. It will find your id_rsa
and prompt you for the passphrase
如果还没有,请重新启动命令提示符,然后运行start-ssh-agent
. 它将找到您id_rsa
并提示您输入密码
Update 2019 - A better solution if you're using Windows 10:OpenSSH is available as part of Windows 10 which makes using SSH from cmd/powershell much easier in my opinion. It also doesn't rely on having git installed, unlike my previous solution.
2019 年更新 - 如果您使用的是 Windows 10,则是一个更好的解决方案:OpenSSH 作为 Windows 10 的一部分提供,在我看来,这使得从 cmd/powershell 使用 SSH 变得更加容易。与我以前的解决方案不同,它也不依赖于安装 git。
Open
Manage optional features
from the start menu and make sure you haveOpen SSH Client
in the list. If not, you should be able to add it.Open
Services
from the start MenuScroll down to
OpenSSH Authentication Agent
> right click > propertiesChange the Startup type from Disabled to any of the other 3 options. I have mine set to
Automatic (Delayed Start)
Open cmd and type
where ssh
to confirm that the top listed path is in System32. Mine is installed atC:\Windows\System32\OpenSSH\ssh.exe
. If it's not in the list you may need to close and reopen cmd.
Manage optional features
从开始菜单打开并确保您Open SSH Client
在列表中。如果没有,您应该可以添加它。Services
从开始菜单打开向下滚动到
OpenSSH Authentication Agent
> 右键单击 > 属性将启动类型从禁用更改为其他 3 个选项中的任何一个。我有我的设置
Automatic (Delayed Start)
打开 cmd 并键入
where ssh
以确认最上面列出的路径在 System32 中。我的安装在C:\Windows\System32\OpenSSH\ssh.exe
. 如果它不在列表中,您可能需要关闭并重新打开 cmd。
Once you've followed these steps, ssh-agent, ssh-add and all other ssh commands should now work from cmd. To start the agent you can simply type ssh-agent
.
按照这些步骤操作后,ssh-agent、ssh-add 和所有其他 ssh 命令现在应该可以在 cmd 中运行了。要启动代理,您只需键入ssh-agent
.
- Optional step/troubleshooting: If you use git, you should set the
GIT_SSH
environment variable to the output ofwhere ssh
which you ran before (e.gC:\Windows\System32\OpenSSH\ssh.exe
). This is to stop inconsistencies between the version of ssh you're using (and your keys are added/generated with) and the version that git uses internally. This should prevent issues that are similar to this
- 可选步骤/故障排除:如果您使用 git,您应该将
GIT_SSH
环境变量设置为where ssh
您之前运行的输出(例如C:\Windows\System32\OpenSSH\ssh.exe
)。这是为了防止您正在使用的 ssh 版本(以及您的密钥是用它添加/生成的)与 git 内部使用的版本之间的不一致。这应该可以防止与此类似的问题
Some nice things about this solution:
关于这个解决方案的一些好处:
- You won't need to start the ssh-agent every time you restart your computer
- Identities that you've added (using ssh-add) will get automatically added after restarts. (It works for me, but you might possibly need a config file in your c:\Users\User\.ssh folder)
- You don't need git!
- You can register any rsa private key to the agent. The other solution will only pick up a key named
id_rsa
- 每次重新启动计算机时都不需要启动 ssh-agent
- 您添加的身份(使用 ssh-add)将在重新启动后自动添加。(它对我有用,但你可能需要在你的 c:\Users\User\.ssh 文件夹中有一个配置文件)
- 你不需要 git!
- 您可以向代理注册任何 rsa 私钥。另一个解决方案只会拿起一个名为
id_rsa
Hope this helps
希望这可以帮助
回答by RaymondChou
One could install Git for Windowsand subsequently run ssh-add
:
Step 3: Add your key to the ssh-agent
To configure the ssh-agent program to use your SSH key:
If you have GitHub for Windows installed, you can use it to clone repositories and not deal with SSH keys. It also comes with the Git Bash tool, which is the preferred way of running git commands on Windows.
Ensure ssh-agent is enabled:
If you are using Git Bash, turn on ssh-agent:
# start the ssh-agent in the background ssh-agent -s # Agent pid 59566
If you are using another terminal prompt, such as msysgit, turn on ssh-agent:
# start the ssh-agent in the background eval $(ssh-agent -s) # Agent pid 59566
Add your SSH key to the ssh-agent:
ssh-add ~/.ssh/id_rsa
要配置 ssh-agent 程序以使用您的 SSH 密钥:
如果您安装了 Windows 版 GitHub,您可以使用它来克隆存储库而不是处理 SSH 密钥。它还附带了 Git Bash 工具,这是在 Windows 上运行 git 命令的首选方式。
确保 ssh-agent 已启用:
如果您使用的是 Git Bash,请打开 ssh-agent:
# start the ssh-agent in the background ssh-agent -s # Agent pid 59566
如果您正在使用其他终端提示,例如 msysgit,请打开 ssh-agent:
# start the ssh-agent in the background eval $(ssh-agent -s) # Agent pid 59566
将您的 SSH 密钥添加到 ssh-agent:
ssh-add ~/.ssh/id_rsa
回答by Brian Ng
If you are trying to setup a key for using git with ssh, there's always an option to add a configuration for the identity file.
如果您尝试设置一个密钥以将 git 与 ssh 一起使用,则始终可以选择为身份文件添加配置。
vi ~/.ssh/config
Host example.com
IdentityFile ~/.ssh/example_key
回答by 030
In order to run ssh-add
on Windows one could install git using choco install git
. The ssh-add
command is recognized once C:\Program Files\Git\usr\bin
has been added as a PATH variable and the command prompt has been restarted:
为了ssh-add
在 Windows上运行,可以使用 .git 安装 git choco install git
。ssh-add
一旦将命令C:\Program Files\Git\usr\bin
添加为 PATH 变量并重新启动命令提示符,就会识别该命令:
C:\Users\user\Desktop\repository>ssh-add .ssh/id_rsa
Enter passphrase for .ssh/id_rsa:
Identity added: .ssh/id_rsa (.ssh/id_rsa)
C:\Users\user\Desktop\repository>
回答by farizmamad
I have been in similar situation before. In Command prompt, you type 'start-ssh-agent' and voila! The ssh-agent will be started. Input the passphrase if it asked you.
我以前也遇到过类似的情况。在命令提示符下,您输入“start-ssh-agent”,瞧!ssh-agent 将启动。如果它询问您,请输入密码。
回答by Arne Olafson
The Git GUI for Windows has a window-based application that allows you to paste in locations for ssh keys and repo url etc:
适用于 Windows 的 Git GUI 有一个基于窗口的应用程序,允许您粘贴 ssh 密钥和 repo url 等的位置: