How to generate a public key?

0137

To generate a public key, you can use the ssh-keygen command. Here are the steps:

  1. Open your terminal.

  2. Run the following command:

    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    
    • -t rsa specifies the type of key to create (RSA).
    • -b 4096 specifies the number of bits in the key (4096 is recommended for better security).
    • -C "your_email@example.com" adds a comment (usually your email) to the key.
  3. Follow the prompts:

    • You will be asked where to save the key. Press Enter to accept the default location (~/.ssh/id_rsa).
    • You can also set a passphrase for added security, or press Enter to leave it empty.
  4. Locate your public key: After the process is complete, your public key will be saved in the file ~/.ssh/id_rsa.pub. You can view it with:

    cat ~/.ssh/id_rsa.pub
    

You can now copy this public key to the target system's authorized_keys file to enable SSH access.

0 Comments

no data
Be the first to share your comment!