My problem is that I can\'t push or fetch from GitLab. However, I can clone (via HTTP or via SSH). I get this error when I try to push :
Permission de
I solved git@gitlab.com: Permission denied (publickey)
issue using following instructions
cat ~/.ssh/id_rsa.pub
id_rsa.pub
(public key) to your getlab `Setting -> SSH Keyscat ~/.ssh/id_rsa
id_rsa
(private key) to `Code_repo->git_auth->id_rsaNOTE: Take care of the machine user if you are using root
user in your DockerFile or anywhere else then use sudo su
before running the above commands to get root user public and private keys.
I found this after searching a lot. It will work perfectly fine for me.
ssh-keygen
.ssh
folder.id_rsa.pub
. Open it on notepad. Copy all text from it.Now give it a shot and it will work for sure.
I found the solution in gitlab help.
To create a new SSH key pair:
1. Open a terminal on Linux or macOS, or Git Bash / WSL on Windows.
2. Generate a new ED25519 SSH key pair: ssh-keygen -t ed25519 -C "email@example.com"
2.1 Or, if you want to use RSA: ssh-keygen -o -t rsa -b 4096 -C "email@example.com"
3. Next, you will be prompted to input a file path to save your SSH key pair to... use the suggested path by pressing Enter
4. Once the path is decided, you will be prompted to input a password to secure your new SSH key pair. It's a best practice to use a password, but it's not required and you can skip creating it by pressing Enter twice.
5. Copy your public SSH key to the clipboard by using one of the commands below depending on your Operating System:
macOS: pbcopy < ~/.ssh/id_ed25519.pub
WSL / GNU/Linux (requires the xclip package): xclip -sel clip < ~/.ssh/id_ed25519.pub
Git Bash on Windows: cat ~/.ssh/id_ed25519.pub | clip
6. Navigating to SSH Keys and pasting your public key in the Key field
7. Click the Add key button
I hope it can help some of you!
In my case it did not work in the WSL (Windows Subsystem for Linux).
When I start the WSL, I must
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
Now the connection works.
We can test this with ssh -T git@github.com
notes:
I solved like this..
Generated a key for Windows using this command:
ssh-keygen -t rsa -C "your.email@example.com" -b 4096
but the problem was that after running this command, it popped a line: "Enter file in which to save the key (/c/Users/xxx/.ssh/id_rsa): " Here, I was giving only file name because of which my key was getting saved in my pwd and not in the given location. When I did "git clone ", it was assuming the key to be at "/c/Users/xxx/.ssh/id_rsa" location but it was not found, hence it was throwing error.
At the time of key generation 2 files were generated say "file1" & "file1.pub". I renamed both these files as
file1 -> id_rsa
and
file1.pub -> id_rsa.pub
and placed both in the location "/c/Users/xxx/.ssh/"
Please use git config credential.helper store
if your site is using TLS/SSL.
Hope this works