If you use GitHub, GitLab, or another Git hosting service, you may have noticed that Git sometimes asks for your username and password every time you run git push.
A simple way to solve this is to configure SSH authentication.
SSH keys allow your computer to authenticate securely with a Git server without having to enter your Git account password for every operation.
In this tutorial, we'll configure SSH authentication on Debian 13 (Trixie).
1. Check for Existing SSH Keys
Before generating a new key, check whether you already have one.
Open a terminal and run:
ls -la ~/.ssh
If you see files such as:
id_ed25519– your private key.id_ed25519.pub– your public key.
You can use your existing key and skip to Step 3.
If no such files exist, continue with the next step.
2. Generate a New SSH Key
Ed25519 is the recommended algorithm. It provides strong security and is widely supported.
Run:
ssh-keygen -t ed25519 -C "your-email@example.com"
Replace your-email@example.com with the email address associated with your Git account.
You will be asked where to save the key:
Enter file in which to save the key (/home/user/.ssh/id_ed25519):
Press Enter to use the default location.
Next, you will be asked to enter a passphrase (an additional password protecting your private key).
You have two options:
- Set a passphrase for additional security.
- Leave it empty if you don't want to enter an additional password.
For better security, I recommend using a passphrase together with SSH agent.
3. Start the SSH Agent and Add Your Key
The SSH agent is a service that securely stores unlocked SSH keys and makes them available when needed.
Start the agent:
eval "$(ssh-agent -s)"
Add your private key:
ssh-add ~/.ssh/id_ed25519
If you configured a passphrase earlier, you will be asked to enter it.
Your key is now available to SSH connections using this agent.
4. Add Your Public Key to GitHub or GitLab
Display the public key:
cat ~/.ssh/id_ed25519.pub
Copy the entire output. It should start with ssh-ed25519.
Important: Only copy the file ending in .pub. Never share your private key (id_ed25519) with anyone!
GitHub
- Open the SSH keys settings.
- Click New SSH key.
- Enter a descriptive title, such as
Debian 13 Desktop. - Paste your public key.
- Click Add SSH key.
GitLab
- Open GitLab SSH Keys.
- Click Add new key.
- Paste your public key.
- Add a descriptive title.
- Save your changes.
5. Test Your SSH Connection
For GitHub, run:
ssh -T git@github.com
The first time you connect, SSH may ask whether you trust the server. Verify its host key fingerprint against GitHub's officially published fingerprints before accepting it.
If authentication is successful, you should see a message similar to:
Hi username! You've successfully authenticated,
but GitHub does not provide shell access.
For GitLab, use:
ssh -T git@gitlab.com
6. Change Your Git Remote from HTTPS to SSH
Even if your SSH key is configured correctly, Git may still be using an HTTPS URL to connect to your repository.
Check your current remote configuration:
git remote -v
If the output looks like this:
origin https://github.com/user/repo.git (fetch)
origin https://github.com/user/repo.git (push)
Your repository is still using HTTPS.
To switch to SSH, run:
git remote set-url origin git@github.com:user/repo.git
Replace user/repo with your actual GitHub username and repository name.
Verify the change:
git remote -v
You should now see an SSH URL instead of HTTPS.
7. Automatically Load Your SSH Key on Debian 13
To avoid manually starting the SSH agent and adding your key every time you open a terminal, you can automate the process.
If you're using Bash, edit your .bashrc file:
nano ~/.bashrc
Add the following lines at the end:
# Start SSH agent if needed
if ! ssh-add -l >/dev/null 2>&1; then
eval "$(ssh-agent -s)" >/dev/null
ssh-add ~/.ssh/id_ed25519
fi
Save the file and reload the configuration:
source ~/.bashrc
If necessary, you will be prompted for your passphrase.
This is a convenient solution for standard terminal usage. However, keep in mind that new shell sessions may start separate SSH agents. For more persistent key management, you can also use system-level SSH agent integration or GNOME Keyring.
8. Test Everything with Git Push
Navigate to your Git project directory and run:
git push
If everything is configured correctly, Git will use your SSH key for authentication instead of asking for your Git account password.
Conclusion
Setting up SSH authentication on Debian 13 is a simple way to make working with Git more convenient and secure.
Once you generate your SSH key, add the public key to GitHub or GitLab, and switch your repository's remote URL from HTTPS to SSH, you won't need to enter your Git account password every time you run git push.
If you use a passphrase, the SSH agent will also help you avoid entering it repeatedly while your key remains loaded.