HOWTO- Generate SSH Key

 



Generate SSH Key Pair:

  • Type the following command to generate an SSH key pair. The -t option specifies the type of key to create (in this case, RSA), and the -b option specifies the number of bits in the key (2048 is a common choice).


ssh-keygen -t rsa -b 2048
  • Press Enter. It will prompt you for a location to save the key. The default location is usually fine, so just press Enter.
  • It will also ask you to enter a passphrase. This is an additional layer of security. You can enter a passphrase or leave it blank, but using a passphrase is recommended for better security.
  • Locate Your SSH Key:

    • By default, the keys are stored in the ~/.ssh/ directory. Your private key will be named id_rsa and your public key will be named id_rsa.pub.

  • Display Your Public Key: You can view your public key using the following command:


    • cat ~/.ssh/id_rsa.pub

    Copy the output.
  • Add the Public Key to the Remote Server:

    • Log in to your remote server.

    • Navigate to the ~/.ssh/ directory (create it if it doesn't exist).

    • Open or create a file named authorized_keys (or append to an existing one) and paste the contents of your public key into this file.


    • echo "your_public_key_here" >> ~/.ssh/authorized_keys


    Make sure to replace "your_public_key_here" with the actual public key you copied.
  • Secure Your Private Key:

    • Ensure that your private key (id_rsa) is only readable by you:

    • chmod 600 ~/.ssh/id_rsa


    Now you should be able to SSH into your remote server using the private key. When connecting, the SSH client will use your private key for authentication.

 

Comments

Popular posts from this blog

Obtaining Google Application Credentials for Python Development: A Comprehensive Guide

Flask 101

HOWTO - SSH via Mac Terminal