Added ssh key for Cygwin, but Git allowed permission (publickey)

I have a problem while trying to use Git with Cygwin. I generated and added the ssh key to the GitLab server, and all this works fine through MINGW64 (cloning, extraction, etc.), but I wanted to use Cygwin and found that it does not work.

Although I put a copy of the generated key in the ~ / user / .ssh folder and manually added the key, so "ssh-add -l" prints it to the list, but when I try to get the repository (or any other server command) I just get:

Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 

This seems like a mistake, but maybe I'm doing something wrong. Has anyone got this problem? Thanks.

UPDATE: After updating the version of OpenSSH in Cygwin, the described problem disappeared.

+8
source share
3 answers

The reason for me is because I put my ssh key files in C:\Users\username\.ssh (which is /cygdrive/c/Users/username/.ssh in cygwin), but actually you need to put your ssh keys in ~/.ssh for it to work. These are two different directories.

Run the following command in cygwin to solve my problem.

 cp /cygdrive/c/Users/username/.ssh/* ~/.ssh/ 

Please note that you must replace username with your actual username .

+3
source

The agent should not work only, but your tools should know where the agent is. It is stored in the $SSH_AUTH_SOCK variable, and if it works for you from one terminal, it should not be from the second.

If you want it to work in your NetBeans, you need to enter this variable in the NetBeans environment variables (but you don’t know how to do this so that it is transferred from the Windows environment to the Cygwin terminal in NetBeans).

Or enter it later into the working terminal (possibly using .bashrc or other startup scripts). A simple test case should be echo $SSH_AUTH_SOCK in the MinGW terminal, and then write export SSH_AUTH_SOCK=/the/path/you/got/from/previous/command in the Cygwin terminal.

You can later automate it by storing the variable in some file that you can read in Cygwin.

 # MinGW scriplet echo "export SSH_AUTH_SOCK=$SSH_AUTH_SOCK" >> ~/agent_env # Cygwin scriplet . ~/agent_env 

Then you can use your mingw agent from the cygwin shell.

+1
source

If you used a non-standard file path for your git SSH key pair, you must configure your SSH client to find your SSH git private key for connecting to GitLab.

You need to execute the following commands to fix:

 eval $(ssh-agent -s) ssh-add ~/.ssh/other_id_rsa 
0
source

Source: https://habr.com/ru/post/1243317/


All Articles