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.

IPtables – How to block and unblock IP Addresses in Linux

Updated 14th December 2023

Not long ago, I noticed some strange activity on a server I manage. The server, running Ubuntu 22.04, was receiving high volumes of traffic from a single IP Address. After some investigation, I decided the activity resembled that of web scrapping, so I decided to block the IP Address. Iptables or ufw I hear you

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

How to setup a remote MySQL database connection in PHPStorm

Updated 1st October 2023

PHPStorm is packed full of features designed to make the development process for PHP developers efficient and streamlined. Although Jetbrains have a standalone product for interacting with databases, named DataGrip, PHPStrom ships with the Database Tools and SQL plugin. This tools is powerful, integrated directly within the IDE, and provides a convinient way to intract