Search code examples
sshserverpublic-key-encryptionopenssh

SSH still asks password after copying the public key to Linux server from Windows


Here is the log when ssh

OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3
debug1: Reading configuration data C:\\Users\\x/.ssh/config
debug1: C:\\Users\\x/.ssh/config line 1: Applying options for server-x
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to server-x [10.81.24.118] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\x/.ssh/id_rsa type 0
debug1: identity file C:\\Users\\x/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.7
debug1: compat_banner: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.7 pat OpenSSH* compat 0x04000000
debug1: Authenticating to server-x:22 as 'x'
debug1: load_hostkeys: fopen C:\\Users\\x/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\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: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: xxxxxxx
debug1: load_hostkeys: fopen C:\\Users\\x/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
debug1: Host server-x is known and matches the ECDSA host key.
debug1: Found key in C:\\Users\\x/.ssh/known_hosts:2
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: pubkey_prepare: ssh_get_authentication_socket: No such file or directory
debug1: Will attempt key: C:\\Users\\x/.ssh/id_rsa RSA SHA256:YIkF8FEzeVmk5i/FYJY0Z1IWYtXhRyjHnKOp9++Mmn4 explicit
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]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: password,keyboard-interactive,hostbased
debug1: Next authentication method: keyboard-interactive

Why on the debug information, it does not have the pubkey option debug1: Authentications that can continue: password,keyboard-interactive,hostbased

I tried to update the ssh file .ssh/config

Host server-x IdentityFile ~/.ssh/id_rsa

On the server side, the pub key is saved in authorized_keys.


Solution

  • Why on the debug information, it does not have the pubkey option debug1: Authentications that can continue: password,keyboard-interactive,hostbased

    Public key authentication isn't currently enabled on that host, otherwise you'd see publickey in that list. Someone with root access on that server will need to update /etc/ssh/sshd_config, making sure PubkeyAuthentication is set to yes (and not commented out), and then restart the SSHD daemon.