This error typically occurs when GitLab doesn’t recognize your SSH key. Follow these steps to generate an SSH key and add it to your GitLab account:
Before creating a new SSH key, check if you already have one. Open Command Prompt or PowerShell and run:
dir %userprofile%\.ssh
If you see files named id_rsa.pub
and id_rsa
, you already have an SSH key. If not, proceed to the next step to generate one.
Open Git Bash, and use the following command to generate a new SSH key:
ssh-keygen -t rsa -C "your.tu-email@tudelft.nl"
Replace “your.tu-email@tudelft.nl” with the email you use for your GitLab account. When asked to “Enter a file in which to save the key,” press Enter to accept the default location.
If you are using Git Bash, start the ssh-agent in the background with:
eval `ssh-agent -s`
If you get an error with the above command, try running the ssh-agent as follows in PowerShell:
ssh-agent | Invoke-Expression
Then, add your SSH private key to the ssh-agent. In Git Bash, use:
ssh-add ~/.ssh/id_rsa
First, copy your SSH public key to the clipboard. In Git Bash, you can use:
clip < ~/.ssh/id_rsa.pub
Then, navigate to your GitLab account settings, and click on “SSH Keys” under “User Settings”. Paste your public key into the “Key” field and click “Add key”.
You should now be able to push to your GitLab repository without the “Permission denied (publickey)” error.