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.

How to set up SSH on Raspberry Pi

Updated 16th August 2022

In this post, I am going to show you how to set up SSH on a Raspberry Pi. Step 1: Raspberry Pi config menu First, open a new terminal and execute the command below to open the Raspberry Pi config menu. sudo rasps-config  Select “Interfacing Options” and press ENTER. Then select “SSH” and press ENTER. 

Start WSL2 services on Windows startup

Updated 16th August 2022

In some circumstances, you may want to automatically start your WSL2 (Windows Subsystem for Linux) services on Windows startup such as Apache2, Nginx, and MySQL. Follow along below to learn how to start your services when you boot your machine. Create a startup script The first step is to create a startup script. This is

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