DEV Community

Pheak Pheasa
Pheak Pheasa

Posted on

To generate an SSH key in Ubuntu

To generate an SSH key in Ubuntu, you can follow these steps:

  1. Open the Terminal: You can do this by pressing Ctrl + Alt + T or by searching for "Terminal" in your application menu.

  2. Generate SSH Key: Use the ssh-keygen command to generate a new SSH key pair.

   ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter fullscreen mode Exit fullscreen mode
  • -t rsa: Specifies the type of key to create (RSA is the most common).
  • -b 4096: Sets the key length to 4096 bits for added security.
  • -C "your_email@example.com": This is a comment to help identify the key, typically using your email.
  1. Save the Key: After running the command, you’ll be prompted to choose a location to save the key. Press Enter to accept the default location (~/.ssh/id_rsa), or specify a different location.

  2. Set a Passphrase (optional): You will be asked to enter a passphrase. This adds an extra layer of security to your key. You can press Enter if you don't want a passphrase.

  3. View Your SSH Public Key: After the key is generated, you can display the contents of the public key file.

   cat ~/.ssh/id_rsa.pub
Enter fullscreen mode Exit fullscreen mode
  1. Copy the SSH Key to a Server (if needed): If you are setting up SSH keys for server access, you can copy the public key to the remote server using:
   ssh-copy-id user@server_ip
Enter fullscreen mode Exit fullscreen mode

After following these steps, your SSH key will be set up and ready to use for authentication.

Top comments (0)