I'm currently setting up OCaml on Windows Subsystem for Linux (WSL) and encountering issues with SSH authentication when trying to connect to GitLab. Despite multiple attempts to generate SSH keys (both RSA and ED25519), I keep getting the error message: "[email protected]: Permission denied (publickey)."
Here are the steps I've followed for generating and adding SSH keys:
RSA Key Generation:
- Generated the key with
ssh-keygen -t rsa -b 4096 -C "[email protected]". - Started the SSH agent with
eval "$(ssh-agent -s)". - Added the key to the SSH agent using
ssh-add ~/.ssh/id_rsa. - Added the public key to GitLab.
- Tested the connection with
ssh -T [email protected], expecting "Welcome to GitLab, @myUsername!" but received "Permission denied (publickey)."
ED25519 Key Generation:
- Generated the key with
ssh-keygen -t ed25519 -C "[email protected]". - Started the SSH agent with
eval "$(ssh-agent -s)". - Added the key to the SSH agent using
ssh-add ~/.ssh/id_ed25519. - Added the public key to GitLab.
- Tested the connection with
ssh -T [email protected], expecting "Welcome to GitLab, @myUsername!" but received "Permission denied (publickey)."
Additional Attempts: I also tried importing my existing SSH key from another machine by copying the keys from my Windows file system to WSL. After copying, I followed the previous steps to add the keys to the SSH agent and GitLab but received the same error.
If required I can provide the output to the command ssh -vvvT [email protected]
Any help on resolving this would be greatly appreciated!
The output of running ssh -Tv -i ~/.ssh/id_rsa [email protected] was:
OpenSSH_9.6p1 Ubuntu-3ubuntu13.5, OpenSSL 3.0.13 30 Jan 2024 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to gitlab.com [172.65.251.78] port 22. debug1: Connection established. debug1: identity file /home/myUsername/.ssh/id_rsa type 0 debug1: identity file /home/myUsername/.ssh/id_rsa-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.5 debug1: Remote protocol version 2.0, remote software version GitLab-SSHD debug1: compat_banner: no match: GitLab-SSHD debug1: Authenticating to gitlab.com:22 as 'git' debug1: load_hostkeys: fopen /home/myUsername/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /home/myUsername/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ssh-ed25519 debug1: kex: server->client cipher: [email protected] MAC: compression: none debug1: kex: client->server cipher: [email protected] MAC: compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: SSH2_MSG_KEX_ECDH_REPLY received debug1: Server host key: ssh-ed25519 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 debug1: load_hostkeys: fopen /home/myUsername/.ssh/known_hosts: No such file or directory debug1: load_hostkeys: fopen /home/myUsername/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: hostkeys_find_by_key_hostfile: hostkeys file /home/myUsername/.ssh/known_hosts does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /home/myUsername/.ssh/known_hosts2 does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts does not exist debug1: hostkeys_find_by_key_hostfile: hostkeys file /etc/ssh/ssh_known_hosts2 does not exist The authenticity of host 'gitlab.com (172.65.251.78)' can't be established. ED25519 key fingerprint is SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8. This key is not known by any other names. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'gitlab.com' (ED25519) to the list of known hosts. debug1: ssh_packet_send2_wrapped: resetting send seqnr 3 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: ssh_packet_read_poll2: resetting read seqnr 3 debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 134217728 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_ext_info_client_parse: server-sig-algs=<ssh-ed25519,[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-256,rsa-sha2-512,ssh-rsa,ssh-dss> debug1: kex_ext_info_check_ver: [email protected]=<0> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: get_agent_identities: bound agent to hostkey debug1: get_agent_identities: agent returned 1 keys debug1: Will attempt key: [email protected] ED25519 SHA256:EYG3mvvWn/tBNsq3wWH/TOzYRnS6eozTJxxEU9b1JRw agent debug1: Will attempt key: /home/myUsername/.ssh/id_rsa RSA SHA256:ef6Y43GZ0muC73Cj97vnIS8sH5bn+GXjxEnNWYEsk/Q explicit debug1: Offering public key: [email protected] ED25519 SHA256:EYG3mvvWn/tBNsq3wWH/TOzYRnS6eozTJxxEU9b1JRw agent debug1: Authentications that can continue: publickey debug1: Offering public key: /home/myUsername/.ssh/id_rsa RSA SHA256:ef6Y43GZ0muC73Cj97vnIS8sH5bn+GXjxEnNWYEsk/Q explicit debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. [email protected]: Permission denied (publickey).
And the output of running ssh -Tv -i ~/.ssh/id_ed25519 [email protected] was:
OpenSSH_9.6p1 Ubuntu-3ubuntu13.5, OpenSSL 3.0.13 30 Jan 2024 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files debug1: /etc/ssh/ssh_config line 21: Applying options for * debug1: Connecting to gitlab.com [172.65.251.78] port 22. debug1: Connection established. debug1: identity file /home/myUsername/.ssh/id_ed25519 type 3 debug1: identity file /home/myUsername/.ssh/id_ed25519-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13.5 debug1: Remote protocol version 2.0, remote software version GitLab-SSHD debug1: compat_banner: no match: GitLab-SSHD debug1: Authenticating to gitlab.com:22 as 'git' debug1: load_hostkeys: fopen /home/myUsername/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: curve25519-sha256 debug1: kex: host key algorithm: ssh-ed25519 debug1: kex: server->client cipher: [email protected] MAC: compression: none debug1: kex: client->server cipher: [email protected] MAC: compression: none debug1: expecting SSH2_MSG_KEX_ECDH_REPLY debug1: SSH2_MSG_KEX_ECDH_REPLY received debug1: Server host key: ssh-ed25519 SHA256:eUXGGm1YGsMAS7vkcx6JOJdOGHPem5gQp4taiCfCLB8 debug1: load_hostkeys: fopen /home/myUsername/.ssh/known_hosts2: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts: No such file or directory debug1: load_hostkeys: fopen /etc/ssh/ssh_known_hosts2: No such file or directory debug1: Host 'gitlab.com' is known and matches the ED25519 host key. debug1: Found key in /home/myUsername/.ssh/known_hosts:1 debug1: ssh_packet_send2_wrapped: resetting send seqnr 3 debug1: rekey out after 134217728 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: ssh_packet_read_poll2: resetting read seqnr 3 debug1: SSH2_MSG_NEWKEYS received debug1: rekey in after 134217728 blocks debug1: SSH2_MSG_EXT_INFO received debug1: kex_ext_info_client_parse: server-sig-algs=<ssh-ed25519,[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,rsa-sha2-256,rsa-sha2-512,ssh-rsa,ssh-dss> debug1: kex_ext_info_check_ver: [email protected]=<0> debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: get_agent_identities: bound agent to hostkey debug1: get_agent_identities: agent returned 1 keys debug1: Will attempt key: /home/myUsername/.ssh/id_ed25519 ED25519 SHA256:EYG3mvvWn/tBNsq3wWH/TOzYRnS6eozTJxxEU9b1JRw explicit agent debug1: Offering public key: /home/myUsername/.ssh/id_ed25519 ED25519 SHA256:EYG3mvvWn/tBNsq3wWH/TOzYRnS6eozTJxxEU9b1JRw explicit agent debug1: Authentications that can continue: publickey debug1: No more authentication methods to try. [email protected]: Permission denied (publickey).
ssh -Tv [email protected]. Preferably for both keys:ssh -Tv -i ~/.ssh/id_rsa [email protected],ssh -Tv -i ~/.ssh/id_ed25519 [email protected]