'SSH permission denied from Windows to GitLab (public key)
I'm trying to connect to GitLab from Microsoft Windows using ssh but in response to this command ssh -Tvvv [email protected] I'm getting the following error:
OpenSSH_for_Windows_8.1p1, LibreSSL 3.0.2
debug3: Failed to open file:C:/Users/Saeed/.ssh/config error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_config error:2
debug2: resolving "gitlab.markitasdone.com" port 22
debug2: ssh_connect_direct
debug1: Connecting to gitlab.markitasdone.com [142.93.9.7] port 22.
debug1: Connection established.
debug3: Failed to open file:C:/Users/Saeed/.ssh/id_rsa error:2
debug3: Failed to open file:C:/Users/Saeed/.ssh/id_rsa.pub error:2
debug1: identity file C:\\Users\\Saeed/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.2
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.2 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to gitlab.markitasdone.com:22 as 'git'
debug3: hostkeys_foreach: reading file "C:\\Users\\Saeed/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Saeed/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from gitlab.markitasdone.com
debug3: Failed to open file:C:/Users/Saeed/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug3: order_hostkeyalgs: prefer hostkeyalgs: [email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: reserved 0
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug3: hostkeys_foreach: reading file "C:\\Users\\Saeed/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Saeed/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from gitlab.markitasdone.com
debug3: Failed to open file:C:/Users/Saeed/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug3: hostkeys_foreach: reading file "C:\\Users\\Saeed/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file C:\\Users\\Saeed/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 142.93.9.7
debug3: Failed to open file:C:/Users/Saeed/.ssh/known_hosts2 error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts error:2
debug3: Failed to open file:C:/ProgramData/ssh/ssh_known_hosts2 error:2
debug1: Host 'gitlab.markitasdone.com' is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\Saeed/.ssh/known_hosts:1
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug3: unable to connect to pipe \\\\.\\pipe\\openssh-ssh-agent, error: 2
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\Saeed/.ssh/id_rsa
debug1: Will attempt key: C:\\Users\\Saeed/.ssh/id_dsa
debug1: Will attempt key: C:\\Users\\Saeed/.ssh/id_ecdsa
debug1: Will attempt key: C:\\Users\\Saeed/.ssh/id_ed25519 ED25519 SHA256:oG6rH82EthXFIeexWntA7mmsYb+h/d5lMGXc+2REW0k
debug1: Will attempt key: C:\\Users\\Saeed/.ssh/id_xmss
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected]>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: C:\\Users\\Saeed/.ssh/id_rsa
debug3: no such identity: C:\\Users\\Saeed/.ssh/id_rsa: No such file or directory
debug1: Trying private key: C:\\Users\\Saeed/.ssh/id_dsa
debug3: no such identity: C:\\Users\\Saeed/.ssh/id_dsa: No such file or directory
debug1: Trying private key: C:\\Users\\Saeed/.ssh/id_ecdsa
debug3: no such identity: C:\\Users\\Saeed/.ssh/id_ecdsa: No such file or directory
debug1: Offering public key: C:\\Users\\Saeed/.ssh/id_ed25519 ED25519 SHA256:oG6rH82EthXFIeexWntA7mmsYb+h/d5lMGXc+2REW0k
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug1: Trying private key: C:\\Users\\Saeed/.ssh/id_xmss
debug3: no such identity: C:\\Users\\Saeed/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
[email protected]: Permission denied (publickey).
It is worth noting that I was able to connect to GitLab just one month ago with no problem. Today, when I got the above error, I decided to remove the ssh key and generated another key following GitLab instructions.
From the error, it seems like it's looking for a config file inside the ssh folder. I checked the folder but there's no such file there. Is it mandatory to create a config file for ssh to be able to work again? If so, what content should this file have?
Update:
The output of ls -l command inside the .ssh directory is:
total 12
-rw------- 1 saeed saeed 399 Jan 16 18:30 id_ed25519
-rw-r--r-- 1 saeed saeed 91 Jan 16 18:30 id_ed25519.pub
-rw-r--r-- 1 saeed saeed 888 Jan 16 10:20 known_hosts
and the output of id is:
uid=1000(saeed) gid=1000(saeed) groups=1000(saeed),4(adm),20(dialout),24(cdrom),25(floppy),27(sudo),29(audio),30(dip),44(video),46(plugdev),117(netdev)
Solution 1:[1]
Welcome in StackOverflow.
This is the interesting part of your log message:
debug3: Failed to open file:C:/Users/Saeed/.ssh/id_rsa error:2
debug3: Failed to open file:C:/Users/Saeed/.ssh/id_rsa.pub error:2
For some reasons (it's up to you to understand why) that path cannot be accessed. Try opening your file manager and go to that location.
Maybe you have not generated the key from that computer or from that user account, in order to:
- verify that the directory
/Users/Saeed/.sshexists - verify that the file
C:/Users/Saeed/.ssh/id_rsaexists
If not, see how to generate a new SSH key.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Valerio Bozz |
