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

Git and DevOps

🔐 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! 👋


Comments

Search

Cargando buscador...