Search code examples
windowsopenssh

OpenSSH is Unable to Offer Key even though SSH-Add Works to Add New Key


SO I had an issue recently with my old work laptop and needed to access assets and company instances for administrative purposes. I have OpenSSH installed and can normally use it within Powershell, but for some odd reason my config, keys do not work. How come I can't load my key and gain access, but if I convert it to a PK file using Pageant it will work.

The key was originally made on a Macbook and then I transferred it to my windows host. OpenSSH will work on Windows, but will not offer the correct key.

debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:
debug3: hostkeys_foreach: reading file "/dev/null"
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
Warning: Permanently added 'XXX.XX.XX.XX' (ECDSA) to the list of known hosts.
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey 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 after 134217728 blocks
debug2: key: C:\\Users\\richard.barrett/\\.ssh\\Mirantis\\id_rsa (00000145F1EB10A0), explicit, agent
debug2: key: C:\\Users\\richard.barrett/.ssh/Mirantis/id_rsa (00000145F1EB1650)
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
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 53
debug3: input_userauth_banner
=================================== WARNING ====================================
You have accessed a computer managed by Mirantis INC.
You are required to have authorization from Mirantis INC
before you proceed and you are strictly limited to use set out within that
authorization. Unauthorized access to or misuse of this system is prohibited
and constitutes an offence under the Computer Misuse Act 1990.
If you disclose any information obtained through this system without authority
================================================================================
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: Offering public key: RSA SHA256:
 C:\\Users\\richard.barrett/\\.ssh\\Mirantis\\id_rsa
debug3: send_pubkey_test
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: Offering public key: RSA SHA256:
C:\\Users\\richard.barrett/.ssh/Mirantis/id_rsa
debug3: send_pubkey_test
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
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
delvalle_tc\\richard.barrett@XXX.XX.XX.XXX\: Permission denied (publickey).

But when I convert it using putty gen it will work? I have two openssh keys

~\.ssh\id_rsa
~\.ssh\Mirantis\id_rsa

How can I switch between the two keys?

Furthermore, how can I use my old config from my macbook on my new windows host? OpenSSH keeps using a different config file, I managed to copy out the old keys from my old macbook before it froze, considering I have never tried to transfer keys between two different OS hosts, I was curious if it was normal as I already have a different key in my ~.ssh folder I made a ~\.ssh\Mirantis\ folder but it keeps offering the main key despite me changing the ssh_config in the C:\ProgramData\ssh

I tried following the directions here, but it doesn't really any offerings as to how to set up ssh_config in Windows as an imported config: https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh_server_configuration


Solution

  • Okay well I feel stupid and solved it. I kept getting the permission denied because of the following issue:

    delvalle_tc\\richard.barrett@XXX.XX.XX.XXX\: Permission denied (publickey).
    

    I was using

    ssh ip_address
    

    Solution:

    ssh-add <file_path>
    ssh user@ip_address
    

    I didn't take into account that my username is not richard.barrett and it was trying to pass this off instead of using rbarrett.