ホーム > Home (English) > System > Genkai > Genkai Usage > How to create a key pair on macOS and Linux

How to create a key pair using macOS or Linux

Last update: July 8, 2024

How to create a key pair on macOS and Linux

How to use

$ ssh-keygen -t rsa -f The_name_of_the_private_key_file_to_be_created

Example

  1. Generate a key file.

    $ mkdir ~/.ssh/genkai   ←Create an output directory for the key file (optional)
    $ ssh-keygen -t rsa -f ~/.ssh/genkai/id_rsa   ←Execute the key creation command
    Generating public/private rsa key pair.
    Enter passphrase (empty for no passphrase):   ←Enter your passphrase (not shown)
    Enter same passphrase again:          ←Re-enter your passphrase (not shown)
    Your identification has been saved in /home/user/.ssh/genkai/id_rsa.
    Your public key has been saved in /home/user/.ssh/genkai/id_rsa.pub.
    The key fingerprint is:
    SHA256:WSoYexKnSfG+Wgn3SPJ//XtLHRoF7IJf1OlnrRxFQL4 user@localPC
    The key's randomart image is:
    +---[RSA 3072]----+
    |    ......   |
    +----[SHA256]-----+
    $
    
    • The passphrase is an arbitrary string of characters that you will be asked to enter when logging in via SSH, so please remember it.
    • If you do not set a passphrase, unauthorized login will be possible if your private key is leaked. We strongly recommend that you use a private key protected by a passphrase.
    • Please use uppercase and lowercase letters, numbers, and symbols for your passphrase, and set a string of at least 12 characters.
  2. Check the generated key file using the ls command from the command line and change the permissions so that it can be accessed via SSH.

    • id_rsa is the private key and id_rsa.pub is the public key.
    $ ls -l ~/.ssh/genkai
    合計 8
    -rw------- 1 user group 2655  7月  5 14:17 id_rsa        ←Private key
    -rw-r--r-- 1 user group  575  7月  5 14:17 id_rsa.pub    ←Public key
    $ chmod 700 ~/.ssh/genkai
    $ chmod 600 ~/.ssh/genkai/id_rsa