Skip to main content
When working with Git on Ubuntu, you may find yourself needing to enter a password or access token every time you push to a remote repository. There are two main methods to avoid this:
  • Using SSH Keys (Recommended)
  • Using Git Credential Helper
This is the most secure approach. It generates a cryptographic key pair on your machine and adds the public key to your Git hosting service.
1
Generate an SSH key pair
2
ssh-keygen -t ed25519 -C "[email protected]"
3
Add the SSH key to the SSH agent
4
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
5
Add the public key to your Git hosting service
6
Copy the content of your public key:
7
cat ~/.ssh/id_ed25519.pub
8
Then add it to your hosting service. For GitHub, follow the official guide.
9
Update your remote URL to use SSH
10
git remote set-url origin [email protected]:<username>/<repository>.git

Method 2: Using Git Credential Helper

This method stores your credentials locally. It is less secure than SSH keys but simpler to set up.
# For temporary caching (default is 15 minutes)
git config --global credential.helper cache

# Set cache timeout to 1 hour
git config --global credential.helper 'cache --timeout=3600'

# For storing credentials permanently (less secure)
git config --global credential.helper store
For a more secure credential storage option, consider using the Git Credential Manager (GCM):
sudo dpkg -i <path-to-package>
git-credential-manager configure

Build docs developers (and LLMs) love