How to generate an SSH key pair in Mac OS?

You can generate a key in Mac OS using the ssh-keygen command. You should run it in Terminal. You will be asked for a file in which the key should be saved to and for a passphrase (password) for the key:

This will create a private key written to ~/id_dsa and a public key written to ~/id_dsa.pub. The passphrase is used to protect your key. You will be asked for it when you load your key. You can do that using the following command:

ssh-add ~/id_dsa

6 Comments

  1. Reply February 11, 2016 / 06:10 BrandtSiteGround Team

    Your strong tags should not be literal

    • Reply February 11, 2016 / 15:51 Ivan YordanovSiteGround Team

      Thank you for the report.

  2. Reply February 11, 2016 / 06:12 BrandtSiteGround Team

    Maybe change your example to rsa instead of dsa

    • Reply February 11, 2016 / 15:52 Ivan YordanovSiteGround Team

      Everything would be the same. You just need to use:

      ssh-keygen -t rsa

      when you are creating the key pair.

  3. Reply April 29, 2016 / 18:32 OlgaSiteGround Team

    How i can use SG ssh key ?
    I did key in CP SSH manager
    and dowload it to my mac
    in terminal
    i used ssh-keygen -t rsa
    and follow all the instructions here
    and i copy data from SGssh key to the .ssh/id_rsa
    and try to connect
    with ssh user@domain -p18765
    but
    SG does not allow it by say - Permission denied (publickey)

    What i can do else?

    • Reply May 3, 2016 / 10:40 escalationsSiteGround Team

      Using the cPanel SSH key generation is merely an alternative to creating the key from the terminal. You should use one of the methods, but not both. The step which you seem to have missed in your explanation above is loading the generated key. For more detailed information, please refer to the article below:

      https://www.siteground.com/kb/how_to_log_in_to_my_shared_account_via_ssh_in_mac_os/

* (Required)