how to add/install a public key in windows? [duplicate]

I'm trying to login to a windows pc from another windows pc using putty on the client pc and openssh on server pc. I can already connect to the said pc by entering username and password. But I wanted to login using key pair that I already generated using puttygen. How am I going to add the public key to the server (windows pc)? Where do I put the public key?

Additional information:

I managed to add the public key by using winscp from the client computer to install the public key to the server at the location: c:/users/myusername/.ssh/authorized_keys.

But when I try to login using the privatekey it says "the server refused our key". I have read that I have to put permissions to the .ssh folder and to the authorized_keys file for it to work. Ive seen examples on this but in linux, but how to exactly do this on windows?

There's only one user in the machine im trying to login and it's also the administrator if that info helps.

6

1 Answer

Usually you will add your public key to:

 > C:\Users\myUserName.myDomainName\.ssh\id_rsa.pub 

If it is not in there, you can paste the public key into the file.

 ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAQBp2eUlwvehXTD3xc7jek3y41n9fO0A+1234567ZAvuqrwNcR2K7UXPVVkFmTZBes3PNnab4UkbFCki23tP6jLzJx/MufHypXprSYF3x4RFh0ZoGtRkr/J8DBKE8UiZIPUeuaaaaaaXztvP+pVXT+HfSnLdN62lXTxLUp9EBZhe3Eb/5nwFaKNpFg1r5NLIpREU2H6fIepi9z28rbEjDj71Z+GOKDXqYWacpbzyIzcYVrsFq8uqOIEh11111R9H0k4lRhKNlIANyGADCMisGWwmIiPJUIRtWkrQjUOvabcdefgcofuxKaWaF5NqwKCc5FDVzsysaL5IM9/gij8837QN7z rsa-key-20141103 

(Note that this is not my or anyone elses public or private key, this is only a demo key.)

Save the file and close the text editor.

You can now specify where your key is by browsing to the key in the "Auth" configuration option as per image:

enter image description here

This link can serve as a guidance aas to how to go about the whole process in more detail if the above is not clear enough.

Usage from client-side (ssh)

  1. Generate a key pair on the client (preferably with a passphrase):

    ssh-keygen -t rsa -f id_rsa

  2. Register private key with ssh-agent (optional, for single sign-on experience)

    net start ssh-agent
    ssh-add id_rsa

  3. Login using private key

    ssh -i .\id_rsa user@host (workgroup user)
    ssh -i .\id_rsa -l user@domain host (domain user)

Setup server-side (sshd)

  1. Append contents of id_rsa.pub (client's public key) to the following file in corresponding user's directory (create one if needed).

    %systemdrive%\Users\.ssh\authorized_keys

  2. Double check access permissions on authorized_keys (only System, Administrators and owner can have access).

    icacls %systemdrive%\Users\.ssh\authorized_keys

4

You Might Also Like