Back

How to create a new SSH key pair

To create a new SSH key pair, run the "ssh-keygen" utility on your local machine. The "ssh-keygen" utility is available on all major operating systems. In macOS or Linux, run "ssh-keygen" in the Terminal app. On Windows, run "ssh-keygen" in the Command Prompt app.

You will be asked to provide the file name and password for a new key pair. Press Enter to accept the default file name.

~$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/user/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/user/.ssh/id_rsa.
Your public key has been saved in /Users/user/.ssh/id_rsa.pub.

To view the public key, run (assuming the default file name):

~$ cat ~/.ssh/id_rsa.pub

A text, similar to the one below, will appear on your screen. This is your public key:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQDVvbA1YdzrWvx00QP27Z6uuMJvmxi3AjMcFQtkkZUX55slzQnAhqUuibCLy3IsOA9SJwLmNb0KBGUjWFXyRvOeNRmIQ8YUB1wjOdCK8CV25nOSWZsW1uwWqKAStyxfvPQniVJGXjRLb30N83BMh39vwpU78xJ1i7nCW2h8FB47b/R0jwKvC0lSgNjtasFTjx9DCe49IOTNXMTVlWD9u9kGpMfneLqvHIkwch7eA0lov0stfIBE9xV2GWHy6F6EXbxiBEkbVR7y8cexG6yMyrBDxVZpmqd0DcAdOAS7gALbSLodFJ3DVTkX6wpdEmi/kLyUGvHN3Elr5+h0EUDFVP7iXBRVq/ic/wLDFEdcBR+bFfuNauAvG96wFA+IbIoreFOveyGosEWhgYH5+biDJ0fZqkZI8zqZqt6ofP8LkzJ5pTZEpnQiLS3C1ST/1mbAwIFwgMD62/BaTGcAkesWb16c+vDZGsMl4MUqWU/5ExkhefKsxmu4fBD676Sqlkavdpk=

Suggested Articles

  • Linux administration

    Connecting to a remote server via SSH

  • Linux administration

    How to replace password-based SSH authentication with key-based