13

I am trying to get my ssh public key from my windows client to ubuntu host, but I have no idea how to. I tried to find the authorized_keys file, but had zero success. ssh-copy-id command did not work from windows. I generated the public/private key pair in PuTTYgen. I am using OpenSSH on the Ubuntu host. Any ideas on what to do?

5 Answers 5

6

Any ideas on what to do?

1. EDIT Download cmder or use your favorite console emulator. Move your public key (id_rsa.pub) and your private key (id_rsa) to C:\Users\yourUserName\.ssh\ create the .ssh folder if needed.

2. On your windows host via cmder:

cp C:\Users\yourUserName\.ssh\id_rsa.pub C:\Users\yourUserName\authorized_keys

3. On your ubuntu host:

service ssh status Start sshd if necessary

mkdir ~/.ssh/ (if it doesn't already exist)

4. On your Windows host via cmder:

cd C:\Users\yourUserName\

scp authorized_keys login-id@ubuntu-Host-Ip:~/.ssh

5. On your Ubuntu host:

chmod 700 ~/.ssh

chmod 600 ~/.ssh/authorized_keys

6. On your Windows host via cmder:

Test if you can ssh into your ubuntu host without login/pw auth. If yes:

rm C:\Users\yourUserName\authorized_keys

(you might encounter difficulties running your ssh-agent on windows, write a comment if so)

1
  • Are you sure that PuTTYgen has generated a C:\Users\yourUserName\.ssh\id_rsa.pub? Aug 22, 2017 at 8:17
4

Do this on your Windows

  1. Give default values without passphrase, just press enter for all

     ssh-keygen -t rsa
    
  2. If the authorized_keys file is not there in target Linux machine else just copy the Windows ~/.ssh/id_rsa.pub content to authorized_keys file in target machine

     scp ~/.ssh/id_rsa.pub [linux_user]@[linux_IP/linux_hostname]:~/.ssh/authorized_keys
    

That's it!!!

1
  • Works perfectly, but careful since this will overwrite the existing "authorized_key"-file. If you want to use multiple keys you can just create multiple files named "authorized_key2", "authorized_key3" etc.
    – Lew Pérez
    Mar 29, 2019 at 15:46
4

ssh-copy-id is missing from windows but it easy to create one!

  • open powershell and type:
notepad $profile
  • You’ll either open the existing Profile.ps1 file, or be prompted to create a new one. At the notepad paste the following function:
function ssh-copy-id([string]$sshHost)
{
    cat ~/.ssh/id_rsa.pub | ssh "$sshHost" "mkdir -p ~/.ssh && touch ~/.ssh/authorized_keys && chmod -R go= ~/.ssh && cat >> ~/.ssh/authorized_keys"
}
  • Close the notepad and save.

  • Finally open a new powershell window and the ssh-copy-id will works as at linux. Example:

ssh-copy-id user@host
0

Assuming your ssh agent is running, just run this from Ubuntu.

ssh-add -L >> ~/.ssh/authorized_keys
0

Another way to send your public key from your Windows to your Linux machine is command in your powershell:

cat ~/.ssh/id_rsa.pub | ssh user@host "cat >> ~/.ssh/authorized_keys"

That should be a one-stop shop for it to work to make it a passwordless entry.

1
  • This is no different from the other PowerShell answer ...
    – schroeder
    Jun 20, 2022 at 8:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .