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:
- HTTPS: You push to a URL, and every time Git asks for your username and password.
- 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.)
- Go to your GitHub account.
- Navigate to Settings โ SSH and GPG Keys.
- 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! ๐