How to generate an SSH key and add to authorized_keys

· Linux · SSH · Ubuntu

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


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.

Related Posts

Start WSL2 services on Windows startup

Updated 16th August 2022

Start Windows Subsystem for Linux services

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

The Ultimate guide to create Apache2 Virtual Hosts (2022)

Updated 16th August 2022


In this post, I will be creating Virtual Hosts for Apache2 on WSL2 (Windows Subsystem for Linux). Follow along with this Ultimate guide to create Apache2 Virtual Hosts. The steps in this tutorial can be carried over onto any environment running Apache2. What we’ll cover Creating the directory structure Creating a symbolic link in Ubuntu

Setting up SSH with BitBucket

Updated 16th August 2022

Setting up your project using a remote repository over SSH can become a painful task for new and even the most seasoned developers. In this article we cover how to set up BitBucket SSH. Repositories not found, incorrect permissions and issues when using your SSH key can all occur, and become very stressful. Below are