How to run ssh-add on windows?

后端 未结 7 540
夕颜
夕颜 2020-11-29 16:22

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.

The problem is ho

相关标签:
7条回答
  • 2020-11-29 16:59

    The Git GUI for Windows has a window-based application that allows you to paste in locations for ssh keys and repo url etc:

    https://gitforwindows.org/

    0 讨论(0)
  • 2020-11-29 17:06

    If you are not using GitBash - you need to start your ssh-agent using this command

    start-ssh-agent.cmd
    

    This is brutally buried in the comments and hard to find. This should be accepted answer.

    If your ssh agent is not set up, you can open PowerShell as admin and set it to manual mode

    Get-Service -Name ssh-agent | Set-Service -StartupType Manual
    
    0 讨论(0)
  • 2020-11-29 17:06

    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:

    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> 
    
    0 讨论(0)
  • 2020-11-29 17:07

    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.

    0 讨论(0)
  • 2020-11-29 17:18

    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.

    vi ~/.ssh/config
    
    Host example.com
    IdentityFile ~/.ssh/example_key
    
    0 讨论(0)
  • 2020-11-29 17:24

    Original answer using git's 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

    Make sure your id_rsa file is in the folder 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

    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.

    1. Open Manage optional features from the start menu and make sure you have Open SSH Client in the list. If not, you should be able to add it.

    2. Open Services from the start Menu

    3. Scroll down to OpenSSH Authentication Agent > right click > properties

    4. Change the Startup type from Disabled to any of the other 3 options. I have mine set to Automatic (Delayed Start)

    5. Open cmd and type where ssh to confirm that the top listed path is in System32. Mine is installed at C:\Windows\System32\OpenSSH\ssh.exe. If it's not in the list you may need to close and reopen 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.

    1. Optional step/troubleshooting: If you use git, you should set the GIT_SSH environment variable to the output of where ssh which you ran before (e.g C:\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

    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

    Hope this helps

    0 讨论(0)
提交回复
热议问题