How to Create SSH Keys with OpenSSH on MacOS or Linux | DigitalOcean Documentation (2024)

Validated on 28 Aug 2019 • Last edited on 16 Feb 2024 ssh

DigitalOcean Droplets are Linux-based virtual machines (VMs) that run on top of virtualized hardware. Each Droplet you create is a new server you can use, either standalone or as part of a larger, cloud-based infrastructure.

How to Create SSH Keys with OpenSSH on MacOS or Linux | DigitalOcean Documentation (1) Note

If you’re struggling with SSH and server management, try our managed products Cloudways and App Platform. Cloudways deploys pre-installed software stacks onto Droplets, and App Platform deploys and scales apps directly from your code repository, along with databases and serverless functions, no SSH or server administration required.

The standard OpenSSH suite of tools contains the ssh-keygen utility, which is used to generate key pairs. Run it on your local computer to generate a 2048-bit RSA key pair, which is fine for most uses.

ssh-keygen

The utility prompts you to select a location for the keys. By default, the keys are stored in the ~/.ssh directory with the filenames id_rsa for the private key and id_rsa.pub for the public key. Using the default locations allows your SSH client to automatically find your SSH keys when authenticating, so we recommend accepting them by pressing ENTER.

  Generating public/private rsa key pair.Enter file in which to save the key (/home/username/.ssh/id_rsa): 

How to Create SSH Keys with OpenSSH on MacOS or Linux | DigitalOcean Documentation (2) Warning

If you have previously generated a key pair, you may see a prompt that looks like this:

/home/username/.ssh/id_rsa already exists.Overwrite (y/n)?

If you choose to overwrite the key on disk, you will not be able to authenticate using the previous key anymore. Selecting yes is an irreversible destructive process.

Once you select a location for the key, you’ll be prompted to enter an optional passphrase which encrypts the private key file on disk.

If you enter one, you will have to provide it every time you use this key (unless you are running SSH agent software that stores the decrypted key). We recommend using a passphrase, but you can press ENTER to bypass this prompt.

  Created directory '/home/username/.ssh'.Enter passphrase (empty for no passphrase):Enter same passphrase again: 

This is the last step in the creation process. You now have a public and private key that you can use to authenticate.

Your identification has been saved in /home/username/.ssh/id_rsa.Your public key has been saved in /home/username/.ssh/id_rsa.pub.The key fingerprint is:a9:49:EX:AM:PL:E3:3e:a9:de:4e:77:11:58:b6:90:26 [emailprotected]The key's randomart image is:+--[ RSA 2048]----+| ..o || E o= . || o. o || .. || ..S || o o. || =o.+. ||. =++.. ||o=++. |+-----------------+

From here, you can:

How to Create SSH Keys with OpenSSH on MacOS or Linux | DigitalOcean Documentation (2024)

FAQs

How to create SSH keys with OpenSSH on macOS? ›

Generate a key pair with OpenSSH
  1. Open a terminal/shell. On macOS: A terminal app is already part of the OS by default. ...
  2. Generate key pair. To generate a key pair with OpenSSH, type the following command: ssh-keygen -t ed25519 -C "your_comment_see_below" ...
  3. Select where to store the key pair. ...
  4. Secure the private key.

How to create a SSH key in macOS? ›

To generate SSH keys in macOS, follow these steps:
  1. Enter the following command in the Terminal window. ssh-keygen -t rsa. ...
  2. Press the ENTER key to accept the default location. The ssh-keygen utility prompts you for a passphrase.
  3. Type in a passphrase. You can also hit the ENTER key to accept the default (no passphrase).
Nov 9, 2022

How to generate SSH key in OpenSSH format? ›

Generating an SSH key pair using OpenSSH
  1. Create an RSA key pair by issuing a command on the host that is similar to this command: ssh-keygen -t rsa. You can also create a valid ECDSA key pair for authentication: ssh-keygen -t ecdsa. ...
  2. Associate the public key with a user on the clustered system using the management GUI.

How do I generate a SSH key in Linux? ›

Generate an SSH Key Pair
  1. Run the ssh-keygen command. You can use the -t option to specify the type of key to create. ...
  2. The command prompts you to enter the path to the file in which you want to save the key. ...
  3. The command prompts you to enter a passphrase. ...
  4. When prompted, enter the passphrase again to confirm it.

Where are SSH keys stored on MacOS? ›

By default, the keys are stored in the ~/. ssh directory with the filenames id_rsa for the private key and id_rsa. pub for the public key. Using the default locations allows your SSH client to automatically find your SSH keys when authenticating, so we recommend accepting them by pressing ENTER .

How do I create multiple SSH keys on a Mac? ›

Enable Multiple SSH Keys for UNIX Based OS
  1. Generate another ssh-key. Generate a new ssh-key for your companyAccount . cd ~/.ssh ssh-keygen -t rsa -C "your_email@youremail.com"
  2. Clear previous cached keys. ssh-add -D.
  3. Add Keys. Then add your keys as following - ...
  4. Check added Keys.

What is the OpenSSH format for public key? ›

An SSH2 public key in OpenSSH format will start with "ssh-rsa". The idea behind all of this is that once you have keys on the remote server and your local host, access will be simpler since the server will only grant access to someone who has the matching private key.

How to setup SSH on macOS? ›

Procedure
  1. Open the Apple menu in the upper left corner of the screen, and select "System Preferences...".
  2. Under "Internet & Wireless", select "Sharing".
  3. In the left column of services, enable "Remote Login".
  4. Highlight the "Remote Login" service and enable access for the users you would like to have SSH access.
Oct 8, 2023

How to add an existing SSH key to a Mac? ›

Procedure
  1. Check your home folder for an . ssh subdirectory and check if it contains a config file. ...
  2. Create the ~/. ...
  3. Add the following content to ~/. ...
  4. Open the Terminal application.
  5. Load your key file into the ssh-agent , replacing <FILE> with the actual file name of your key, then type your passphrase, if prompted.

How do I manually generate SSH keys? ›

For Windows 10 & 11
  1. Press the Windows key or open up the Start Menu. Type “cmd”.
  2. Under “Best Match”, click “Command Prompt”.
  3. In the command prompt, use the ssh-keygen command: ...
  4. The system will now generate the key pair and display the key fingerprint and a randomart image. ...
  5. Open your file explorer.

How to set up SSH key? ›

How to set up SSH keys
  1. Create the ssh key pair using ssh-keygen command.
  2. Copy and install the public ssh key using ssh-copy-id command on a Linux or Unix server.
  3. Add yourself to sudo or wheel group admin account.
  4. Disable the password login for root account.
Mar 5, 2024

How to generate SSH key and copy? ›

Copy the ssh key into remote servers
  1. Open a terminal on your local computer.
  2. Generate an SSH key pair if you haven't already done so by running the command: ssh-keygen . ...
  3. Once the key pair is generated, run the command: ssh-copy-id user@remote_server . ...
  4. You'll be prompted to enter the password for the remote user account.
Apr 8, 2023

How to generate an SSH key on Mac? ›

Generate an SSH Key Pair
  1. Open a new Terminal window.
  2. Type ssh-keygen -b 4096 -t rsa.
  3. You will be prompted to enter a filename. By default, your keys will be saved as id_rsa and id_rsa.pub. ...
  4. When prompted, enter a passphrase.
  5. This will created a hidden directory called . ssh that contains both your public (id_rsa.
Feb 7, 2022

How to generate SSH key for Linux VM? ›

VMs accept the key formats listed in the sshd_config file. On Linux and macOS workstations, use the ssh-keygen utility to create a new SSH key pair. The following example creates an RSA key pair. Open a terminal and use the ssh-keygen command with the -C flag to create a new SSH key pair.

How to generate SSH PEM key in Linux? ›

Generate SSH Keys in PEM Format to Connect to a Public or On-Premises sFTP Server
  1. Verify the key by opening the file in Notepad. The key must start with the following phrase. ...
  2. Use -m PEM with ssh-keygen to generate private keys in PEM format: ssh-keygen -t rsa -m PEM.

How do I get my SSH public key on my Mac? ›

To view the SSH public key on macOS
  1. Open your terminal window, and run the command cat ~/.ssh/id_rsa.pub. or cat /Users/USERNAME/.ssh/id_rsa.pub. Where USERNAME is your macOS username.
  2. The above commands will print out your SSH public key.
Jun 29, 2023

How do I create a SSH connection on a Mac? ›

Connecting to a Server via SSH in Terminal
  1. Step 1: Open Terminal. In Finder, open the Applications folder and double click on the Utilities folder. Double click on the Terminal application. ...
  2. Step 2: Enter the standard SSH command. The basic syntax of connecting to SSH is as follows: ssh user@IP-Address.
Apr 20, 2024

How to create SSH config in Mac? ›

How to create the config file
  1. Step 1: Change SSH directory. The first thing you need to do is to change your user SSH directory. ...
  2. Step 2: Create new file. You will now need to create the first configuration. ...
  3. Step 3: SSH into server. To SSH into our Nextcloud server, you'll only have to type the command: ssh nextcloud.
Jul 10, 2023

Top Articles
Latest Posts
Article information

Author: Dong Thiel

Last Updated:

Views: 6206

Rating: 4.9 / 5 (79 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Dong Thiel

Birthday: 2001-07-14

Address: 2865 Kasha Unions, West Corrinne, AK 05708-1071

Phone: +3512198379449

Job: Design Planner

Hobby: Graffiti, Foreign language learning, Gambling, Metalworking, Rowing, Sculling, Sewing

Introduction: My name is Dong Thiel, I am a brainy, happy, tasty, lively, splendid, talented, cooperative person who loves writing and wants to share my knowledge and understanding with you.