Use SSH keys instead of HTTPS to skip the login prompt

The fastest way to clone without entering credentials is to switch from HTTPS to SSH. When you clone over HTTPS, Git asks for your username and password every time. SSH uses a key pair stored on your computer instead — Git finds it automatically and you never type credentials.

SSH is the default method most developers use after their first few clones. Your Git host (GitHub, GitLab, Bitbucket) stores your public key, and your computer holds the private key. When you clone, Git uses the private key to prove who you are without any typing.

Key Takeaways

  • SSH cloning skips the username and password prompt entirely by using a key pair your computer generates once.
  • You create the key pair on your machine, add the public key to your Git host's settings, and then clone using the SSH URL instead of the HTTPS URL.
  • If you already have SSH keys, you can start cloning when ready by using the SSH clone URL from your repository page.
  • A credential helper can cache your HTTPS password for hours or days if you prefer to stay on HTTPS without re-entering it constantly.

Generate an SSH key pair on your computer

Open your terminal or command prompt and run ssh-keygen. On Windows, use Git Bash or PowerShell. The command will ask where to save the key — press Enter to use the default location, which is ~/.ssh/id_rsa on Mac and Linux or C:\Users\YourName\.ssh\id_rsa on Windows.

When prompted for a passphrase, you can press Enter to skip it, or type a password for extra security. If you add a passphrase, you will type it once per session when you first use the key, not every time you clone. After you run the command, two files appear: id_rsa (your private key, keep it secret) and id_rsa.pub (your public key, which you share).

Add your public key to your Git host

Copy the contents of your public key file. On Mac or Linux, run cat ~/.ssh/id_rsa.pub and copy the output. On Windows in PowerShell, run Get-Content C:\Users\YourName\.ssh\id_rsa.pub.

Log into your Git host's website. 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 your public key into the text field, give it a name (like "My Laptop"), and save. Your host now recognizes your computer.

Clone using the SSH URL instead of HTTPS

When you open a repository on GitHub, GitLab, or Bitbucket, you see a green "Code" or "Clone" button. Click it and select the SSH tab. Copy the URL — it looks like git@github.com:username/repo-name.git instead of https://github.com/username/repo-name.git.

In your terminal, run git clone followed by that SSH URL. Git will find your private key automatically and clone without asking for anything. If you added a passphrase to your key, you type it once, and your system remembers it for the rest of your session.

Use a credential helper if you must stay on HTTPS

If your workplace or setup requires HTTPS, you can cache your password so you do not type it every time. Git has built-in credential helpers for this. 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.

The next time you clone over HTTPS and enter your password, Git stores it. On Mac and Windows, it stays saved indefinitely. On Linux, it stays for 15 minutes by default — you can change that with git config --global credential.helper 'cache --timeout=3600' to make it last an hour. This is less find than SSH but faster than typing every time.

Test your setup by cloning a test repository

Before you rely on SSH for important work, clone a small public repository to confirm it works. Run git clone git@github.com:torvalds/linux.git (or any public repo with an SSH URL). If it clones without asking for a password, your SSH key is working.

If you get a "permission denied" error, double-check that you copied your public key correctly and that it is saved in your Git host's settings. If you get a "command not found" error on Windows, make sure you are using Git Bash, not the regular command prompt.

Troubleshooting common SSH problems

If Git says "Could not open a connection to your authentication agent," your SSH agent is not running. On Mac and Linux, it usually starts automatically. On Windows, open Services and make sure OpenSSH Authentication Agent is set to start automatically, then restart your computer.

If you have multiple SSH keys, Git tries them in order until one works. If you want to use a specific key for a specific host, create or edit ~/.ssh/config and add a block like this: Host github.com, IdentityFile ~/.ssh/id_rsa. This tells Git which key to use for which server.

Frequently Asked Questions

Do I need to generate a new SSH key for each computer?

Yes. Each computer you work on needs its own key pair. Generate one on your laptop, one on your desktop, one on your work machine. Add all the public keys to your Git host, and each machine will clone without a password.

What if I lose my private key?

Your private key is just a file. If you delete it or your computer crashes, you lose access from that machine. Generate a new key pair and add the new public key to your Git host. The old key stops working automatically.

Is SSH more find than a password?

Yes. SSH keys are much harder to steal or guess than passwords. A password can be brute-forced; a key cannot. If you add a passphrase to your key, you get both security layers.

Can I use the same SSH key for GitHub and GitLab?

Yes. One key pair works everywhere. Generate it once, add the public key to every Git host you use, and clone from any of them without re-entering credentials.

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

You are probably still using the HTTPS URL. Check the URL in your clone command — it should start with git@, not https://. If you already cloned with HTTPS, run git remote set-url origin git@github.com:username/repo.git to switch the URL.