Page cover image

Transferring keys to Remote Server from Windows

Public key location on Windows

  • Typically, the public key file (ragnar.pub) should be located in the same directory as the private key file (ragnar.pem) on your Windows terminal.

  • The default location for SSH keys on Windows is "C:\Users<username>.ssh".

  • In your case, the public key is correctly located at "C:\Users\Tim Hannon.ssh\ragnar.pub".

Copying the public key to the Ubuntu server

  • To enable SSH key-based authentication, you need to copy the public key from your Windows terminal to the Ubuntu server.

  • On your Windows terminal, open the Command Prompt or PowerShell and navigate to the directory where your SSH keys are located:

C:\Users\Tim Hannon\.ssh\
  • Use the scp command to securely copy the public key file to the Ubuntu server:

scp ragnar.pub [email protected]:~/.ssh/authorized_keys

This command copies the "ragnar.pub" file to the Ubuntu server's "~/.ssh/authorized_keys" file. Replace "ragnar" with the appropriate username on the Ubuntu server if it differs.

  • You will be prompted to enter the password for the "ragnar" user on the Ubuntu server.

How SSH key-based authentication works

  • SSH key-based authentication provides a secure way to log in to a remote server without using a password.

  • When you generate an SSH key pair, it creates two files: a private key and a public key.

  • The private key (ragnar.pem) stays on your local machine (Windows terminal) and should be kept secure. It acts as a secret key that proves your identity.

  • The public key (ragnar.pub) is meant to be uploaded to the remote server (Ubuntu server) you want to access.

  • When you attempt to log in to the Ubuntu server using SSH, your local machine presents the private key to the server.

  • The Ubuntu server checks if the corresponding public key exists in the "~/.ssh/authorized_keys" file on the server.

  • If the public key matches the private key you are using, the server grants you access without requiring a password.

To connect to the Ubuntu server using SSH key-based authentication, follow these steps:

  1. Open the Command Prompt or PowerShell on your Windows terminal.

  2. Navigate to the directory where your private key file (ragnar.pem) is located:

cd C:\Users\Tim Hannon\.ssh\

Use the ssh command to connect to the Ubuntu server:

ssh -i ragnar.pem [email protected]

This command specifies the private key file to use for authentication.

  1. If the SSH key-based authentication is set up correctly, you should be logged in to the Ubuntu server without being prompted for a password.

Remember to keep your private key file secure and do not share it with anyone. If you need to set up SSH key-based authentication for multiple servers, you can copy the same public key to each server's "~/.ssh/authorized_keys" file.

Last updated

Was this helpful?