Windows 10 SSH keys

后端 未结 11 1681
难免孤独
难免孤独 2020-12-12 14:57

I am having a really hard time getting my SSH keys up and running after installing Windows 10. Normal method is create it and throw it in the user\'s account under .ssh. T

相关标签:
11条回答
  • 2020-12-12 15:01
    1. Open the windows command line (type "cmd" on the search box and hit enter).
    2. It'll default to your home folder, so you don't need to cd to a different one.
    3. Type mkdir .ssh
    0 讨论(0)
  • 2020-12-12 15:04

    I found a notable exception that in Windows 10, using the described route only wrote the files to the folder if the file names where not specified in the ssh-keygen generator.

    giving a custom key name caused the files containing the RSA public and private keys not to be written to the folder.

    • Open the windows command line
    • Type ssh-keygen
    • Leave file name blank, just press return,
    • Set your passphrase
    • Generate your key files. They will now exist. and be stored in c:/Users/YourUserName/.ssh/

    (using Admin Command Line and Windows 10 Pro)

    0 讨论(0)
  • 2020-12-12 15:09

    Create private/public key:

    1. Open up terminal (git bash, PowerShell, cmd.exe etc.)
    2. Type in ssh-keygen
    3. Press enter for default file save (~/.ssh/id_rsa)
    4. Press enter for default passphrase (no passphrase)
    5. Press enter again
    6. Look at the output and make sure that the RSA is 3072 or above

    You have now created a private/public key pair.

    For GIT the key must have a strength of 2048, must be located in the users .ssh directory and be called id_rsa and id_rsa.pub. When pasting the keys anywhere make sure to use a program that does not add new lines like VIM.

    0 讨论(0)
  • 2020-12-12 15:13

    2019-04-07 UPDATE: I tested today with a new version of windows 10 (build 1809, "2018 October's update") and not only the open SSH client is no longer in beta, as it is already installed. So, all you need to do is create the key and set your client to use open SSH instead of putty(pagent):

    1. open command prompt (cmd)
    2. enter ssh-keygenand press enter
    3. press enter to all settings. now your key is saved in c:\Users\.ssh\id_rsa.pub
    4. Open your git client and set it to use open SSH

    I tested on Git Extensions and Source Tree and it worked with my personal repo in GitHub. If you are in an earlier windows version or prefer a graphical client for SSH, please read below.

    2018-06-04 UDPATE:

    On windows 10, starting with version 1709 (win+R and type winver to find the build number), Microsoft is releasing a beta of the OpenSSH client and server. To be able to create a key, you'll need to install the OpenSSH server. To do this follow these steps:

    1. open the start menu
    2. Type "optional feature"
    3. select "Add an optional feature"
    4. Click "Add a feature"
    5. Install "Open SSH Client"
    6. Restart the computer

    Now you can open a prompt and ssh-keygen and the client will be recognized by windows. I have not tested this. If you do not have windows 10 or do not want to use the beta, follow the instructions below on how to use putty.


    ssh-keygen does not come installed with windows. Here's how to create an ssh key with Putty:

    1. Install putty
    2. Open PuttyGen
    3. Check the Type of key and number of bytes to use
    4. Move the mouse over the progress bar
    5. Now you can define a passphrase and save the public and private keys

    For openssh keys, a few more steps are required:

    1. copy the text from "Public key for pasting" textbox and save it as "id_rsa.pub"
    2. To save the private key in the openssh format, go to Conversions->Export OpenSSH key ( if you did not define a passkey it will ask you to confirm that you do not want a pass key)
    3. Save it as "id_rsa"

    Now that the keys are saved. Start pagent and add the private key there ( the ppk file in Putty's format)

    Remember that pagent must be running for the authentication to work

    0 讨论(0)
  • 2020-12-12 15:13

    Warning: If you are saving your keys under C:/User/username/.ssh ( the default place), make sure to back up your keys somewhere (eg your password manager).

    After the most recent Windows 10 Update (version 1607), my .ssh folder was empty. This is where my keys have always been, but Windows decided to delete them when updating.

    Thankfully I had backed up my keys... But... I bet some people will be reverting their PC's today.

    0 讨论(0)
  • 2020-12-12 15:15

    If you have Windows 10 with the OpenSSH client you may be able to generate the key, but you will have trouble copying it to the target Linux box as the ssh-copy-id command is not part of the client toolset.

    Having has this problem I wrote a small PowerShell function to address this, that you add to your profile.

    function ssh-copy-id([string]$userAtMachine, [string]$port = 22) {   
        # Get the generated public key
        $key = "$ENV:USERPROFILE" + "/.ssh/id_rsa.pub"
        # Verify that it exists
        if (!(Test-Path "$key")) {
            # Alert user
            Write-Error "ERROR: '$key' does not exist!"            
        }
        else {  
            # Copy the public key across
            & cat "$key" | ssh $userAtMachine -p $port "umask 077; test -d .ssh || mkdir .ssh ; cat >> .ssh/authorized_keys || exit 1"      
        }
    }
    

    You can get the gist here

    I have a brief write up about it here

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