SSH & GPG Setup
1. SSH Configuration
Secure Shell (SSH) keys are used for secure authentication with GitLab/GitHub without typing your password every time.
Generate SSH Key
Linux / macOS
- Open Terminal.
- Generate a new ED25519 SSH key:bash
ssh-keygen -t ed25519 -C "your_email@example.com" - Press Enter to accept the default file location.
- Enter a secure passphrase (recommended).
Windows
- Open PowerShell as Administrator.
- Ensure OpenSSH Client is installed:powershell
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0 - Start the SSH Agent service:powershell
Start-Service ssh-agent Set-Service -Name ssh-agent -StartupType 'Automatic' - Generate the key:powershell
ssh-keygen -t ed25519 -C "your_email@example.com" - Add the key to the agent:powershell
ssh-add $env:USERPROFILE\.ssh\id_ed25519 - Configure Git to use Windows OpenSSH:powershell
git config --global core.sshCommand "C:/Windows/System32/OpenSSH/ssh.exe"
Add SSH Key to GitLab
- Copy your public key:
- Linux/Mac:
cat ~/.ssh/id_ed25519.pub - Windows:
Get-Content $env:USERPROFILE\.ssh\id_ed25519.pub
- Linux/Mac:
- Go to GitLab Profile → Edit Profile → SSH Keys.
- Paste the key and click Add key.
2. GPG Configuration (Standard Signing)
GPG keys are used to sign your commits, verifying that they actually came from you.
Install GPG
- macOS:
brew install gnupg pinentry-mac - Linux (Debian/Ubuntu):
sudo apt install gnupg - Windows:
winget install GnuPG.Gpg4win
Generate GPG Key
- Generate a key:bash
gpg --full-gen-key - Select (9) ECC (sign and encrypt) and (1) Curve 25519.
- Set expiration (0 for no expiration).
- Enter your name and email (must match your Git email).
- Set a passphrase.
Configure Git to use GPG
List keys to get the ID:
bashgpg --list-secret-keys --keyid-format LONGCopy the ID after
sec(e.g.,30F2B65B9246B6CA).Export public key for GitLab:
bashgpg --armor --export <YOUR_KEY_ID>Paste this into GitLab Profile → GPG Keys.
Tell Git to use this key:
bashgit config --global user.signingkey <YOUR_KEY_ID> git config --global commit.gpgsign trueSet the GPG program path (if needed):
- Windows:
git config --global gpg.program "C:/Program Files (x86)/GnuPG/bin/gpg.exe" - Linux/Mac:
git config --global gpg.program $(which gpg)
- Windows:
3. Alternative: SSH Commit Signing
You can use your existing SSH key to sign commits instead of GPG. This is simpler if you already have SSH set up.
Configure Git for SSH Signing
Set the format to SSH:
bashgit config --global gpg.format sshSet the signing key to your SSH public key:
bashgit config --global user.signingkey "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA..."(Replace with the content of your
.pubfile)Enable signing:
bashgit config --global commit.gpgsign true
Windows Specifics for SSH Signing
If using Windows, ensure Git uses the correct SSH keygen tool:
git config --global gpg.ssh.program "C:/Windows/System32/OpenSSH/ssh-keygen.exe"4. Git Identity
Ensure your local Git identity matches your GitLab account.
git config --global user.name "Your Name"
git config --global user.email "your.email@example.com"