How to Generate an SSH key pair in Ubuntu, you can use the ssh-keygen commandHow to Generate

Posted by

Generating an SSH key pair in Ubuntu is a straightforward process that can greatly enhance the security of your connections to remote servers. Here’s how to do it step-by-step:

Open Terminal: You can do this by pressing Ctrl+Alt+T on your keyboard or by searching for “Terminal” in your applications menu.

Generate the SSH Key Pair: Use the ssh-keygen command to create a new SSH key pair. You can specify the algorithm with the -t option. The most common algorithms are rsa, dsa, ecdsa, or ed25519. Here is an example using ed25519, which is currently recommended for its strength and performance:

    ssh-keygen -t ed25519
    

    You can also specify the filename and location for the key pair with the -f option. If you omit this, the keys will be stored in the default location (~/.ssh/id_ed25519 for the private key and ~/.ssh/id_ed25519.pub for the public key).

    Enter a Passphrase (Optional): After issuing the command, you will be prompted to enter a passphrase. This adds an extra layer of security by encrypting your private key with the passphrase. It’s optional but recommended. If you prefer not to use a passphrase, just press Enter to skip.

    Check Your SSH Keys: After the keys are generated, you can check them by listing the contents of your ~/.ssh directory:

    ls ~/.ssh
    

    You should see your newly created key pair listed there, typically named as id_ed25519 and id_ed25519.pub.

    Copy the Public Key to Your Server: To use the SSH key, you’ll need to copy the public key to your server. You can do this manually or use the ssh-copy-id utility if you have password SSH access to the server:

    ssh-copy-id -i ~/.ssh/id_ed25519.pub username@remote_host
    

    Replace username with your actual username on the server and remote_host with the server’s IP address or hostname.

    Connect Using Your SSH Key: Once the public key is placed in the server’s authorized_keys file, you can connect to it using your SSH key:

    ssh -i ~/.ssh/id_ed25519 username@remote_host
    

      guest
      0 Comments
      Inline Feedbacks
      View all comments
      0
      Would love your thoughts, please comment.x
      ()
      x