How to Generate an SSH Key on Unix (Debian, Ubuntu, and Git Bash for Windows)

๐Ÿ” How to Generate an SSH Key on Unix Systems (Ubuntu, Debian, and Git Bash for Windows)

Today Iโ€™ll show you how to generate an SSH key โ€” a method that makes working with Git (especially GitHub and GitLab) much easier.


๐Ÿค” Why Use SSH Instead of HTTPS?

There are two common ways to work with remote Git repositories:

  1. HTTPS: You push to a URL, and every time Git asks for your username and password.
  2. SSH: You authenticate with a secure key, and Git wonโ€™t ask for your credentials again โ€” it's fast and secure.

๐Ÿ› ๏ธ Steps to Generate Your SSH Key

1. Open your terminal

This works on any Unix-based system โ€” Debian, Ubuntu, macOS, or even Git Bash on Windows.

Run the following command:

ssh-keygen

Youโ€™ll see a prompt like this:

Generating public/private rsa key pair.
Enter file in which to save the key (/home/your-user/.ssh/id_rsa):

Just press Enter to use the default location.

Then it will ask for a passphrase. You can leave it empty or set one for extra security.


2. Locate Your SSH Key

Once completed, your key will be stored in the ~/.ssh folder. To display the public key, run:

cd ~/.ssh
cat id_rsa.pub

Youโ€™ll see something like this:

ssh-rsa AAAAB3... your_email@example.com

Copy everything from that line โ€” it's your public key.


๐Ÿ”— Use It with GitHub (or GitLab, etc.)

  1. Go to your GitHub account.
  2. Navigate to Settings โ†’ SSH and GPG Keys.
  3. Click New SSH Key, give it a name, and paste the contents of your id_rsa.pub.

Done! Now you can push and pull from GitHub without entering your credentials every time.


โœ… Final Notes

SSH keys make your life easier, especially if you're pushing code often. No more typing passwords!

Until next time! ๐Ÿ‘‹