How to Create a Public/Private Key Pair (System Administration Guide: Security Services) (2024)

How to Create a Public/Private Key Pair

The standard procedure for creating a Secure Shell public/private key pair follows. For information on additional options, see ssh-keygen(1).

  1. Start the key generation program.


    myLocalHost% ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key(/home/johndoe/.ssh/id_rsa): 
  2. Enter the path to the file that will hold the key.

    By default, the file name id_rsa, which represents an RSA v2 key, appears in parentheses. You can select this file by pressing Return. Or, you can type an alternative filename.


    Enter file in which to save the key(/home/johndoe/.ssh/id_rsa): <Return>

    The public key name is created automatically and the string .pub is appended to the private key name.

  3. Enter a passphrase for using your key.

    This passphrase is used for encrypting your private key. A good passphrase is 10–30 characters long, mixes alphabetic and numeric characters, and avoids simple English prose and English names. A null entry means no passphrase is used, but this entry is strongly discouragedfor user accounts. Note that the passphrase is not displayed when you type it in.


    Enter passphrase(empty for no passphrase): <Type the passphrase>
  4. Re-enter the passphrase to confirm it.


    Enter same passphrase again: <Type the passphrase>Your identification has been saved in /home/johndoe/.ssh/id_rsa.Your public key has been saved in /home/johndoe/.ssh/id_rsa.pub.The key fingerprint is:0e:fb:3d:57:71:73:bf:58:b8:eb:f3:a3:aa:df:e0:d1 johndoe@myLocalHost
  5. Check the results.

    The key fingerprint (a colon-separated series of 2 digit hexadecimal values) is displayed. Check that the path to the key is correct. In the example, the path is /home/johndoe/.ssh/id_rsa.pub. At this point, you have created a public/private key pair.

  6. Copy the public key and append the key to the $HOME/.ssh/authorized_keys file in your home directory on the remote host.

How to Create a Public/Private Key Pair (System Administration Guide: Security Services) (2024)

FAQs

How do I create a public private key pair? ›

To generate an SSH private/public key pair for your use, you can use the ssh-keygen command-line utility. You can run the ssh-keygen command from the command line to generate an SSH private/public key pair. If you are using Windows, by default you may not have access to the ssh-keygen command.

How do I create a public and private key on my server? ›

Unix-like operating systems:
  1. Access the Terminal, which you can find via Search.
  2. Enter the following command in the Terminal window: ssh-keygen -t rsa.
  3. Choose a file path where your keys will be saved. ...
  4. You can now set up a password for your key pair.

How do I generate a public private key pair in RSA? ›

Windows Users
  1. Start the PuTTYgen utility, by double-clicking on its .exe file.
  2. For Type of key to generate, select RSA.
  3. In the Number of bits in a generated key field, specify either 2048 or 4096 (increasing the bits makes it harder to crack the key by brute-force methods. ...
  4. Click the Generate button.
Apr 12, 2023

How to generate public private key pair for SFTP? ›

To obtain an SFTP private key as a user, log in to JSCAPE MFT Server through the Web User Interface. Once inside, click the link labeled My Account at the upper-right corner of the screen. Next, navigate to the section Public Key Authentication and then click Generate Key Pair.

Can I make my own private key? ›

It is possible to make your own private keys in a low-tech way that is sufficiently random, such as recording a large series of dice rolls. You can also use a website such as Bitaddress, which will generate the public and private keys for you as hexadecimal addresses and Quick Response (QR) codes.

How do I create a private key key? ›

Procedure
  1. Open the command line.
  2. Create a new private key. openssl genrsa -des3 -out key_name .key key_strength -sha256 For example, openssl genrsa -des3 -out private_key.key 2048 -sha256. ...
  3. Create a certificate signing request (CSR).

What is an example of a public private key? ›

Public and private keys: an example

Bob wants to send Alice an encrypted email. To do this, Bob takes Alice's public key and encrypts his message to her. Then, when Alice receives the message, she takes the private key that is known only to her in order to decrypt the message from Bob.

How do I publish a public key to my server? ›

How to Add SSH Public Key to Server
  1. Method 1: Automatically copy the ssh key to server.
  2. Method 2: Manually copy the public ssh key to the server. Step 1: Get the public key. Step 2: Create ssh directory in the user's home directory (as a sysadmin) Step 3: Set appropriate permission to the file.

How do I add a public key to my Windows server? ›

You can use Session (Tabs) > Install Public Key into Server command on the main window, or Tools > Install Public Key into Server command on SSH > Authentication page page on Advanced Site Settings dialog. The functionality of the command is similar to that of OpenSSH ssh-copy-id command.

What is a private public key pair? ›

Every digital certificate contains a public key. The public key and its associated private key, which is not part of the certificate, together make up a key-pair. They were generated at the same time and are mathematically linked. Each certificate that you create has a key-pair.

Where do I get a RSA private key? ›

The Private Key is always generated alongside the CSR as a pair. Its exact location depends on the server it was generated on. Most server types and tools: Upon generating a CSR, the Private Key will be located in the same directory as the CSR.

How to generate public and private key using ssh-keygen? ›

Generating an SSH Key Pair on UNIX and UNIX-Like Platforms Using the ssh-keygen Utility
  1. Navigate to your home directory: ...
  2. Run the ssh-keygen utility, providing as filename your choice of file name for the private key: ...
  3. Enter a passphrase for the private key, or press Enter to create a private key without a passphrase:

How do I create a public and private key for SFTP in Windows? ›

Generating an SSH key
  1. Open the PuTTYgen program.
  2. For Type of key to generate, select SSH-2 RSA.
  3. Click the Generate button.
  4. Move your mouse in the area below the progress bar. ...
  5. Type a passphrase in the Key passphrase field. ...
  6. Click the Save private key button to save the private key.
Nov 9, 2022

How to generate private key from SSL? ›

There are 2 ways to get to the Private key in cPanel:
  1. Using SSL/TLS Manager. On the cPanel home page, click on “SSL/TLS Manager” and then on the “Private keys” button. ...
  2. Using File Manager. Click on the File Manager button from the cPanel home screen and open the window like on the screenshot below.

What is the difference between a private key and a public key? ›

To conclude, private keys can be used for both encryption and decryption, while Public keys are used only for the purpose of encrypting the sensitive data. Private keys are shared between the sender and the receiver, whereas public keys can be freely circulated among multiple users.

How many public keys can a private key generate? ›

While you can generate a public key with a private key, doing the opposite is practically impossible because of the one-way “trapdoor” function. You can have any number of public keys connected to a private key.

Can a hacker get private key? ›

Applications (software) and devices can be hacked. Because private keys are stored in application and device wallets, hackers can access them and steal your cryptocurrency.

What is the difference between a certificate and a public key? ›

The owner of the key pair makes the public key available to anyone, but keeps the private key secret. A certificate verifies that an entity is the owner of a particular public key. Certificates that follow the X. 509 standard contain a data section and a signature section.

Where can I get a private key? ›

Windows (IIS)

On Windows servers, the OS manages your certificate files for you in a hidden folder, but you can retrieve the private key by exporting a “. pfx” file that contains the certificate(s) and private key. Open Microsoft Management Console (MMC). In the Console Root expand Certificates (Local Computer).

What are the two types of public key? ›

The public key algorithms in use today are:
  • Rivest-Shamir-Adleman (RSA)
  • Elliptic Curve Digital Signature Algorithm (ECDSA)
  • Digital Signature Algorithm (DSA)
  • Diffie-Hellman key agreement protocol.

What is the format of private key? ›

PKCS #8. This format can contain private keys and encrypted private key information. It stores the data in base64 encoded data, usually using a DER or PEM structure which is then encrypted.

What are public private key authentication methods? ›

The public key authentication protocol uses two keys per node, a public key for encryption and a private key for decryption. Everybody has access to the public key of a node, while the private key is secret. During authentication, random numbers are generated and exchanged, similar to the shared secret key protocol.

Who certifies public keys? ›

It is issued by a trusted organization and provides identification for the bearer. A trusted organization that issues public key certificates is known as a Certificate Authority (CA). The CA can be likened to a notary public. To obtain a certificate from a CA, one must provide proof of identity.

How do I add a public key to my instance? ›

To add a public SSH key to instance metadata using the Google Cloud console, do the following:
  1. In the Google Cloud console, go to the VM instances page. ...
  2. Click the name of the VM that you want to add an SSH key for.
  3. Click Edit.
  4. Under SSH Keys, click Add item.
  5. Add your public key into the text box. ...
  6. Click Save.

How do I give someone a public key? ›

To give someone else access to your server's user, simply add their public key on a new line in your authorized_keys file, just as you would add your own. To revoke access for that person, remove that same line and save the changes.

How to create public key from SSL? ›

OpenSSL: Create a public/private key file pair [top]
  1. You will need to have OpenSSL installed.
  2. Create a new directory on your C drive and give it an appropriate name (i.e., Test).
  3. Open a Command Prompt window and go to the new directory. ...
  4. Type the path of the OpenSSL install directory, followed by the RSA key algorithm.

Where are public keys stored in Windows? ›

Your public SSH key is located by default at C:\Users\<username>\. ssh\id_rsa. pub and is perfectly safe to be shared with anyone.

Does the public key go on the client or server? ›

The private key for the server is usually stored with the server configuration and the public key is transmitted by the server when you attempted to connect.

Can 2 people have the same public key? ›

Yes. In asymmetric cryptography, key pairs are randomly generated. Furthermore, the amount of different keypairs that can be generated is huge. Therefore, the probability of two people accidentally generating the same keypair is negligible.

Do public private key pairs expire? ›

PGP public keys can be used to encrypt files up to the day they expire. Once the key expires it can no longer be used to encrypt data. A private key will continue to decrypt data that was encrypted by that public key, even after the public key expires.

What is the difference between key pair and access key? ›

Access keys are for users who have create and own instance. Key pairs are for those who are users of ec2 instance. Users don't need to share access keys of owner as they don't need to create resources thus maintaining separation of concern.

Is RSA private key same as private key? ›

RSA key is a private key based on RSA algorithm. Private Key is used for authentication and a symmetric key exchange during establishment of an SSL/TLS session. It is a part of the public key infrastructure that is generally used in case of SSL certificates.

What is the difference between public key and RSA public key? ›

Note that RSAPublicKey extends PublicKey and that both are Java interfaces. In general you should yourself only use RSAPublicKey if you require the additional methods offered by the interface. This should not often be the case; for the cryptographic operations the PublicKey usually suffices.

How to generate private key from certificate Windows? ›

Assign the existing private key to a new certificate
  1. Sign in to the computer that issued the certificate request by using an account that has administrative permissions.
  2. Select Start, select Run, type mmc, and then select OK.
  3. On the File menu, select Add/Remove Snap-in.
  4. In the Add/Remove Snap-in dialog box, select Add.
Jan 24, 2022

How to generate SSH public key with email? ›

Generating a new SSH key #
  1. Open Terminal .
  2. Paste the text below, substituting in your GitHub email address. $ ssh-keygen -t ed25519 -C "your_email@example.com" ...
  3. At the prompt, type a secure passphrase. For more information, see "Working with SSH key passphrases."

Can I create private key using public key? ›

You cannot generate private key from public key but you can generate public key from the private key using puttygen.

How to provide the private key in SSH command? ›

Step 1 Create and Copy Private Key to remote VM
  1. Copy private key to new file called centos7template01.txt.
  2. Type ls to verify file is there.
  3. Copy file to remote VM.
  4. Type yes to connect and transfer file.
  5. SSH into remote VM (Cent7-07)
  6. Type ls to confirm file copied successfully.

Does SFTP use public or private key? ›

SSH in SFTP Servers is an encrypted network protocol that uses public key cryptography to create a more secure method to authenticate a client's identity and rights to access a server.

Does SFTP need a public key? ›

SFTP authentication using private keys is generally known as SFTP public key authentication, which entails the use of a public key and private key pair. The two keys are uniquely associated with one another in such a way that no two private keys can work with the same public key.

How to generate private key for SSL certificate in SAP? ›

Procedure
  1. Create a key pair for the server by running the following command:   keytool -genkeypair -alias server -keyalg RSA -keysize 1024 -dname "cn=<server>, o=SAP, l=Dublin, st=CA, c=US" -keypass sybase -ext bc:c -validity 3650 -keystore server.jks -storepass sybase. ...
  2. Generate a certificate request for a server.

How do I get a public and private key from a certificate? ›

Access the private key by exporting a “.pfx” file that contains the certificate and private key.
  1. Open Microsoft Management Console.
  2. In the Console Root, expand Certificates (Local Computer)
  3. Locate the certificate in the Personal or Web Server folder.
  4. Right click the certificate.
  5. Select Export.
  6. Follow the guided wizard.
Aug 19, 2022

Is SSL certificate a private key? ›

Your private key is the single most important component of your SSL certificate. It's what gives you the power to authenticate your website to internet users, helps to enable encryption and prevents others from impersonating you.

What is an example of a private and public key pair? ›

Public and private keys: an example

Bob wants to send Alice an encrypted email. To do this, Bob takes Alice's public key and encrypts his message to her. Then, when Alice receives the message, she takes the private key that is known only to her in order to decrypt the message from Bob.

What is the tool which creates a public private key pair in Windows? ›

You can create a key pair using the Strong Name tool (Sn.exe).

What is the difference between public key and public private key? ›

In the pair of keys, the public key is for encrypting the plain text to convert it into ciphertext, and the private key is used for decrypting the ciphertext to read the message. The private key is given to the receiver while the public key is provided to the public.

What are public and private keys for beginners? ›

A public key can be given to any person with whom an individual wants to communicate, whereas a private key belongs to the individual it was created for and isn't shared. The public key is typically stored on a public key infrastructure server and is used to encrypt data securely before it is sent over the internet.

How many keys exist in a public private key pair? ›

There are 2 keys that exist in the public and private key pair. The public key is known to every user and comes into play to encrypt the message while the private key is owned by the owner and no other user knows it and it comes into play to decrypt the received encrypted message.

Which of the following commands is used to create a private and public key pair? ›

The ssh-keygen command creates two files, one public and one private, for the local computer.

Who provides the private key? ›

A private key, also known as a secret key, is a variable in cryptography that is used with an algorithm to encrypt and decrypt data. Secret keys should only be shared with the key's generator or parties authorized to decrypt the data.

How do I verify a public private key pair? ›

Follow the steps below in a terminal window to verify a public and private key are a pair:
  1. openssl x509 -noout -modulus -in <public.crt> | openssl md5 > /tmp/crt.pub. Note: Replace <public. ...
  2. openssl rsa -noout -modulus -in <private.key> | openssl md5 > /tmp/key.pub. Note: Replace <private. ...
  3. diff /tmp/crt.pub /tmp/key.pub.

Why do public and private keys need to be generated in pairs? ›

A public key is an encryption method that uses a pair of private and public keys to secure data communication. First, the public key encrypts the plain text, converting it into ciphertext, then the private key is used for decrypting the converted ciphertext so the recipient can read the message.

Top Articles
Latest Posts
Article information

Author: Tuan Roob DDS

Last Updated:

Views: 5745

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Tuan Roob DDS

Birthday: 1999-11-20

Address: Suite 592 642 Pfannerstill Island, South Keila, LA 74970-3076

Phone: +9617721773649

Job: Marketing Producer

Hobby: Skydiving, Flag Football, Knitting, Running, Lego building, Hunting, Juggling

Introduction: My name is Tuan Roob DDS, I am a friendly, good, energetic, faithful, fantastic, gentle, enchanting person who loves writing and wants to share my knowledge and understanding with you.