How to Configure Git Pushes Without Authentication Prompts

4 min read

If you’re entering a username and password every time you run git push, your remote is using HTTPS. Switch to SSH authentication and you’ll never see a credentials prompt again. This guide shows you how to configure git pushes without authentication prompts for GitHub, GitLab, and Bitbucket.

The examples here are run on WSL2 Ubuntu in Windows, but they work the same on any Linux or macOS system.

Step 1: Generate an SSH Key

Create an Ed25519 SSH key pair on your local machine:

ssh-keygen -t ed25519 -C "you@example.com"

Press Enter to accept the default file location (~/.ssh/id_ed25519). You can set a passphrase or leave it empty for fully passwordless pushes.

If your system doesn’t support Ed25519 (older SSH versions), use RSA instead:

ssh-keygen -t rsa -b 4096 -C "you@example.com"

Step 2: Start the SSH Agent and Add Your Key

Start the SSH agent and add your private key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519

To avoid running this every time you open a terminal, add these lines to your ~/.bashrc (or ~/.zshrc if you use Zsh):

if [ -z "$SSH_AUTH_SOCK" ]; then
    eval "$(ssh-agent -s)" > /dev/null
    ssh-add ~/.ssh/id_ed25519 2> /dev/null
fi

This starts the agent only if it isn’t already running.

Step 3: Add the Public Key to Your Git Host

Copy your public key:

cat ~/.ssh/id_ed25519.pub

Select and copy the output. Then add it to your Git hosting service:

Service Where to Add
GitHub Settings > SSH and GPG keys > New SSH key
GitLab Preferences > SSH Keys > Add new key
Bitbucket Personal settings > SSH keys > Add key

Paste the public key, give it a name (e.g., “WSL Ubuntu”), and save.

Step 4: Test the Connection

Verify that SSH authentication works:

ssh -T git@github.com

For GitLab or Bitbucket, replace github.com with gitlab.com or bitbucket.org.

A successful response looks like:

Hi username! You've successfully authenticated, but GitHub does not provide shell access.

If you see Permission denied (publickey), check that your key was added correctly in Step 3 and that the SSH agent has the key loaded (ssh-add -l).

Step 5: Switch Existing Repos from HTTPS to SSH

If your existing repos still use HTTPS remotes, you need to switch them to SSH. Check the current remote URL:

git remote -v

If the URL starts with https://, switch it to SSH:

# GitHub
git remote set-url origin git@github.com:username/repo.git

# GitLab
git remote set-url origin git@gitlab.com:username/repo.git

# Bitbucket
git remote set-url origin git@bitbucket.org:username/repo.git

Replace username and repo with your actual values. You can find the SSH URL on the repository page under the “Clone” button — select “SSH” instead of “HTTPS.”

Verify the change:

git remote -v

The URL should now start with git@ instead of https://.

Step 6: Push Without Credentials

Now push normally — no password prompt:

git push origin main

This works for all Git operations: push, pull, fetch, and clone. When cloning new repos, use the SSH URL from the start:

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

Using Multiple SSH Keys (GitHub + GitLab)

If you use different SSH keys for different services, create an SSH config file to route each host to the correct key:

nano ~/.ssh/config
Host github.com
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_ed25519_github

Host gitlab.com
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/id_ed25519_gitlab
chmod 600 ~/.ssh/config

SSH uses the matching Host entry to pick the right key automatically. For the same approach on remote servers, see How to Setup Passwordless SSH Login on EC2 Ubuntu 22.04.

Troubleshooting

Issue Fix
Still asked for a password after switching to SSH Run git remote -v — the URL may still be HTTPS. Switch it with git remote set-url origin git@...
Permission denied (publickey) Check ssh-add -l to see if your key is loaded. If empty, run ssh-add ~/.ssh/id_ed25519
Key works for GitHub but not GitLab Add the same public key to both services, or use separate keys with an SSH config file
SSH agent resets after closing terminal Add the agent startup snippet from Step 2 to your ~/.bashrc

Conclusion

Generate an SSH key, add it to your Git host, switch your remotes from HTTPS to SSH, and you’re done. No more password prompts on push, pull, or clone.

To keep your Git version current, see How to Upgrade Git to Version 2.41.0 or Later on Ubuntu. If you want to enforce code quality before each commit, check out How to Install and Use Pre-commit on Ubuntu WSL 2.