How to generate an SSH key and add to authorized_keys

By Dillon Smart · · · 1 Comments

In this article we explain how to generate a SSH key for your local machine and add your public key to the authorized_keys on a remote server.

Generate an SSH key for Windows, MAC and Linux

Note: If you are using Windows, we recommend you use a SSH client like PuTTY.

For MAC/Linux run:

ssh-keygen -t rsa

The ssh-keygen program will prompt you for the location of the key file. Press Return to accept the defaults.

You can optionally set a passphrase to protect your key. Press Return to skip this step.\

Add your SSH key to a remote servers authorized_keys

Note: You will need access to the remote server

First copy your public key you have just generated. Your public key has the .pub extension when generated using ssh-keygen.

Next on the remote server, open the authorized_keys file and paste your public key.

nano ~/.ssh/authorized_keys

Now your local machine can use SSH to login on the remote server.

ssh username@remote-host-name-or-ip

LinuxSSHUbuntu

1 Comment

I Know That Now

[…] Note: It is best practice to connect to remote servers using either a strong unique password or using an SSH key pair. Refer to How to generate an SSH key pair and add to authorized_keys on remote server. […]

Was this helpful? Leave a comment!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

The ULTIMATE guide to setup Windows Subsystem for Linux (WSL) with Ubuntu, Apache2, MySQL and PHP

Updated 16th August 2022

Windows is now good for development! Yes! All thanks to Windows Subsystem for Linux (WSL). No more WAMP or Xampp, WSL can do everything you need. In this ultimate guide to setup Windows Subsystem for Linux with Ubuntu, Apache2, MySQL, and PHP we will cover: What is Windows Subsystem for Linux? Setting up Windows Subsystem

What is a Cron Job and how to write to the Crontab

Updated 10th December 2023

The need to schedule tasks on a machine is common for any Software Developer, System Admin or IT professional, so it’s important to learn what a cron job is and how to write to the crontab. What is CRON? Cron is a daemon built-in to most Unix-like operating systems such as: Cron reads the crontab (cron tables)

WSL vs Dual Boot speed test

Updated 16th August 2022

In this experiment, I will be using WSL2 running Ubuntu 20.04 and Ubuntu 20.04 dual-booted on the same Dell XPS. Is there a noticeable difference? Follow along for the results of the WSL vs Dual Boot speed test. If you are like me and use different development environments a lot, you may find the results