Introducing : Managed Cloud Hosting Services is on Beta on BatchNepal 🎉🎉
// //

How to create SSH Keys - Complete Tutorial

Added by

at August 26, 2024

How to create SSH Keys  - Complete Tutorial - BatchNepal

SSH keys are a pair of cryptographic keys used to authenticate a user or device in the Secure Shell (SSH) protocol. They provide a more secure and convenient alternative to password-based logins for accessing remote servers and services. In this guide, we will learn how to create ssh keys using PuTTYgen and command line. 

Components of SSH Keys

  1. Private Key: This key remains on the client machine and should be kept secret. It is used to decrypt messages that were encrypted with the corresponding public key and to sign messages, ensuring the authenticity of the client. 

  2. Public Key: This key is placed on the server you want to access. It is used to encrypt messages that only the corresponding private key can decrypt, and to verify signatures made with the corresponding private key.

How SSH Keys Work

When you attempt to connect to a server using SSH keys, the following steps occur:

  1. Key Pair Generation: You generate a pair of keys (private and public) on your local machine using a tool like ssh-keygen.

  2. Public Key Placement: You copy the public key to the remote server's ~/.ssh/authorized_keys file. This grants access to the user associated with that public key.

  3. Authentication Process:

    • The client requests access to the server.
    • The server sends a challenge (a random string) encrypted with the client’s public key.
    • The client decrypts the challenge using its private key and sends it back to the server.
    • The server verifies the response. If the response is correct, the server grants access.

Benefits of SSH Keys

  1. Security: SSH keys are much harder to crack compared to passwords. They use strong encryption algorithms, making brute-force attacks impractical.

  2. Convenience: Once set up, SSH keys allow passwordless logins, making it easier to script and automate tasks that require SSH access.

  3. No Need for Password Sharing: Public keys can be shared openly without compromising security, unlike passwords.

How to Generate SSH Keys

1. Generate the SSH Key Pair using ssh-keygen:

 ssh-keygen -t rsa -b 4096 -C "[email protected]" 
  • -t ed25519: Specifies the type of key to create (ed25519 is a modern algorithm).
  • -C "[email protected]": Adds a comment (often used to identify the key).
This command generates a 4096-bit RSA key pair. You will be prompted to specify a file to save the key (default is ~/.ssh/id_rsa) and optionally set a passphrase for extra security.
2. Generate the SSH Key Pair using PuTTYgen :
PuTTY is an open-source SSH and telnet client, developed originally by Simon Tatham for the Windows platform. PuTTY and PuTTYgen come together in a bundle. 
  • Go to https://putty.org and download the latest putty installer and proceed to install it on windows.
  • Once installed, you will see puttygen available with putty. 
  • Now click on PuTTYgen and open it.
  • Click on Generate button and hover around blank area to generate randomness of your ssh keys.
  • On Key Comment, enter the name of your ssh key.
  • On Key Passphrase, enter a strong password and re-enter it on confirm passphrase input field.
  • Now save your public and private keys using their respective buttons.  Private keys have .ppk and public keys have .pub extension when created from PuTTYgen. 

Puttygen SSH key generate

Conclusion

SSH keys provide a secure and efficient way to authenticate to remote servers. By using a key pair (private and public keys), we can enhance security, streamline access, and enable secure automation of tasks.

Related Topics

[Solved] Unknown at rule @tailwind warning in VS Code
//
file_type_tailwind
TailwindCss
//
[Solved] Unknown at rule @tailwind warning in VS Code

In this guide, we will see methods to fix "unknown at rule@tailwind" error in VS Code.

August 26, 2024

Boost Your Online Presence with the Best SEO Agency in Nepal
// //
Boost Your Online Presence with the Best SEO Agency in Nepal

In this guide, we will learn why should you not ignore SEO for your business and how it impacts your business growth.

August 26, 2024

Malicious javascript injected into 100k websites
Malicious javascript injected into 100k websites

Polyfill.js has been found injecting malicious code and performing supply chain attack to visitors.

August 26, 2024

Automating Django Deployment with Github Actions
// //
Automating Django Deployment with Github Actions

In this guide we will learn how to automate django deployment simply using github actions

August 26, 2024

How to Deploy Django to Production
// //
How to Deploy Django to Production

This simple guide includes all steps required to host a django website in production with ease.

November 24, 2024