0/1 Lessons

Introduction to Linux Server Operating Systems

• 30min

0 / 3 lessons complete

Linux Server Installation and Lab Setup

• 23min

0 / 6 lessons complete

Working with the Linux Command Line Interface

• 1hr 30min

0 / 12 lessons complete

User and Group Management

• 44min

0 / 7 lessons complete

Linux Storage

• 30min

0 / 6 lessons complete

Linux Administration Basics

• 53min

0 / 8 lessons complete

Linux Networking

• 47min

0 / 8 lessons complete

Course Conclusion

• 5min

0 / 1 lessons complete

SSH Config and SSH Key Pairs


Q&A (0)

Resources (0)

Saving Progress...


There are no resources for this lesson.

In this lesson, you will learn how to generate an SSH key pair on both Windows and Linux, and how to use it for a secure connection to a virtual machine running Ubuntu Server on VirtualBox. By the end of this lesson, you'll be able to create your own keys, copy the public key to your server, and configure SSH to automatically use your private key for a seamless and secure connection.

Generating an SSH Key Pair on Windows

Let's generate a SSH Key Pair. You will generate private and public key, store the private key on your local computer (host computer), and store the public key on your destination server (Ubuntu Server VM). This allows for a more secure (and passwordless, if desired) authentication.

The commands below will work on any Linux or up to date Windows machine. The Windows 10 April 2018 update and Windows 11 include the OpenSSH client by default, which comes with the ssh-keygen utility

  • Open Command Prompt or PowerShell: You can search for it in the Start menu.
  • Run ssh-keygen: Type the following command and press Enter:
ssh-keygen -b 4096
  • Follow the prompts to create your key pair. You'll be asked to choose a file to save the key and to enter a passphrase (optional but recommended for additional security).

  • Locate the SSH Keys: The public and private keys will be saved in the .ssh directory within your user's home directory (C:\Users\<your_username>\.ssh by default). The public key typically has a .pub extension

Copying the Public Key to our target server

The next step involves getting the public key on to our Ubuntu Server VM. This is where there will be specific instructions depending on whether you're using Windows or Linux.


Now that you have your SSH key pair, the next step is to copy the public key to your Ubuntu Server VM. The VM in this scenario is named "Ubuntu Server" with the hostname ubuntu-server and has the IP address It's also connected to a bridged network adapter.

  1. Copy the Public Key: Use the ssh-copy-id command from your host machine:bash
ssh-copy-id paulh@

Replace paulh with your username if different. You'll need to enter your VM's password.


Unfortunately Windows does not come with the ssh-copy-id utlity, so we need to write some PowerShell code to do the same thing. Of course, you can manually copy the contents of the public key and place it in the ~/.ssh/authorized_keys file, but this little script will do it for you in a couple lines of code. Be sure to update the $username and $ip_address variables:

$ip_address = ""
$username = "paulh"
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh $username@$ip_address "cat >> .ssh/authorized_keys"

Verify the Connection: Test your SSH connection:

Run the command below to test your connection:

ssh paulh@ -i ~\.ssh\id_rsa

If everything is set up correctly, you should connect to your VM without needing a password. Your Windows host my also try that id_rsa private key by default, so you can try to SSH without specifying the id_rsa file.

Modifying the SSH Configuration File

If you're computer doesn't automatically use the correct ssh key to connect, you will need to make the SSH client on your host automatically use your private key, modify the ssh_config file.

For Windows, In command prompt (not Powershell) console, type the following:

notepad C:\Users\%username%\.ssh\config

In Linux, you can type the following:

nano ~/.ssh/config

Add the Host and IdentityFile Directives:

Host ubuntu-server
    User paulh
    IdentityFile ~/.ssh/id_rsa

Replace id_rsa with the name of your private key file if it's different, and replace the User and HostName values if you're differ.

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Notify of
profile avatar
Inline Feedbacks
View all comments