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


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 Upload and Download files to and from a Linux server over SSH

Updated 16th August 2022

Its common place to need to upload and download files to and from a remote Linux server. To upload and download files from a remote Linux server you can use the scp (secure copy) command. To download a file you can use: To upload a file you can use: scp /path/to/file/your/uploading username@ip-or-server-name:/path/to/location/to/upload/to Note: It is

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

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