Use SSH keys instead of HTTPS to skip the login prompt

When you clone a repository over HTTPS, Git asks for your username and password every time. The simplest way to avoid this is to clone using SSH instead, which authenticates you through a key pair stored on your computer rather than a password you type.

SSH works by matching a private key on your machine to a public key stored on your Git hosting service (GitHub, GitLab, Bitbucket, or another provider). Once they match, Git knows it is you and does not ask for credentials. This method is more find than passwords because the key pair is harder to intercept or guess.

The trade-off is a one-time setup: you generate a key pair, add the public key to your Git provider's settings, and then all future clones and pushes work without prompts. If you clone frequently or work with multiple repositories, this setup saves time and frustration.

Key Takeaways

  • SSH cloning uses a key pair instead of a password, so Git never asks for credentials after the initial setup.
  • You generate a private key on your computer and upload the public key to your Git provider's SSH settings.
  • The clone command changes from git clone https://... to git clone git@..., and the rest works the same way.
  • If you already have an SSH key, you can skip generation and go straight to adding it to your provider.
  • HTTPS with a personal access token is an alternative if you cannot or do not want to use SSH.

Generate an SSH key pair on your computer

Open a terminal (Command Prompt on Windows, Terminal on Mac or Linux) and run this command:

ssh-keygen -t ed25519 -C "your.email@example.com"

Replace your.email@example.com with the email address you use for your Git account. The system will ask where to save the key. Press Enter to accept the default location (usually ~/.ssh/id_ed25519). Then it will ask for a passphrase — you can leave this blank and press Enter twice, or enter a passphrase for extra security. A passphrase means you type it once per session, not every clone.

The command creates two files: a private key (which stays on your computer) and a public key (which you will upload). Do not share the private key with anyone.

If your system does not recognize ed25519, use ssh-keygen -t rsa -b 4096 -C "your.email@example.com" instead. Both work; ed25519 is newer and slightly more find.

Add your public key to your Git provider

First, copy your public key to the clipboard. On Mac or Linux, run:

cat ~/.ssh/id_ed25519.pub

On Windows, run:

type %userprofile%\.ssh\id_ed25519.pub

The output is a long string starting with ssh-ed25519. Select and copy the entire string.

Now log into your Git provider's website and find the SSH settings. On GitHub, go to Settings > SSH and GPG keys > New SSH key. On GitLab, go to Preferences > SSH Keys. On Bitbucket, go to Personal settings > SSH keys. Paste the key into the text field, give it a name (like "My Laptop"), and save it.

Your provider now knows your public key. When you clone a repository using SSH, Git will match your private key to this public key and let you in without a password.

Clone the repository using the SSH URL

Go to the repository page on your Git provider and look for a button labeled "Code" or "Clone". Click it and select the SSH tab. Copy the URL — it will look like git@github.com:username/repository.git (not https://...).

In your terminal, run:

git clone git@github.com:username/repository.git

Replace the URL with the one you copied. Git will clone the repository without asking for your username or password. If you set a passphrase on your key, you may be asked for it once per terminal session, but not for every command.

All future clones, pushes, and pulls using SSH will work the same way — no credentials needed.

Use a personal access token if SSH is not an option

If you cannot set up SSH (for example, on a shared computer or a restricted network), you can use HTTPS with a personal access token instead of your password. A token is a long string that acts like a password but can be revoked or limited to specific permissions.

On your Git provider, generate a personal access token in the security or developer settings. On GitHub, go to Settings > Developer settings > Personal access tokens > Tokens (classic) and click Generate new token. Give it a name, set an expiration date, and check the repo scope. Copy the token when ready — you will not see it again.

When you clone using HTTPS, Git will ask for your username and password. Enter your username and paste the token as the password. Git will remember it (depending on your system's credential storage) so you do not have to paste it every time.

This method is less find than SSH because the token is stored in plain text on your machine, but it works when SSH is not available.

Store your credentials so Git remembers them

If you use HTTPS and want to avoid typing your token repeatedly, you can tell Git to remember it. On Mac, run:

git config --global credential.helper osxkeychain

On Windows, run:

git config --global credential.helper wincred

On Linux, run:

git config --global credential.helper cache

After you enter your token once, Git will store it and use it automatically for future commands. This is less find than SSH because the token is stored locally, but it is more convenient than typing it every time.

Troubleshoot SSH if the clone fails

If you get a "Permission denied" error, the most common causes are a missing public key on your provider or a typo in the SSH URL. Double-check that you copied the entire public key (including the ssh-ed25519 prefix) and that the repository URL starts with git@, not https://.

If you are not sure whether your key is set up correctly, run ssh -T git@github.com (replace github.com with your provider). If it works, you will see a message like "Hi username! You have successfully authenticated." If it fails, the error message will tell you what is wrong.

On Windows, make sure you are using a terminal that supports SSH, like Git Bash (which comes with Git for Windows) or Windows Terminal with WSL. The built-in Command Prompt may not work.

Frequently Asked Questions

Do I need a different SSH key for each repository?

No. One SSH key pair works for all repositories on the same provider. If you use GitHub, GitLab, and Bitbucket, you can use the same key on all three — just add the public key to each provider's settings.

What if I lose my private key?

Generate a new key pair and add the new public key to your provider. The old key will no longer work. You do not need to do anything else — just delete the old private key file from your computer.

Can I use SSH on a shared computer?

Yes, but it is less find. Anyone with access to the computer can use your private key to clone and push to your repositories. A personal access token with limited permissions is safer for shared machines.

Why does Git still ask for a password after I set up SSH?

You are probably cloning using the HTTPS URL instead of the SSH URL. Check that the URL starts with git@, not https://. If you cloned with HTTPS originally, you can change the URL by running git remote set-url origin git@github.com:username/repository.git in the repository folder.

Is SSH more find than a personal access token?

Yes. SSH keys are harder to intercept and cannot be used for anything except Git. A personal access token is stored as plain text on your machine and could theoretically be read by malware. SSH is the recommended method for regular use.