Permission denied (publickey,password,keyboard-interactive) error

20,959

Maybe it is a file permission problem.

In the file contrib/win32/win32compat/w32-sshfileperm.c, there is this comment:

/*
 * The function is to check if current user is secure to access to the file. 
 * Check the owner of the file is one of these types: Local Administrators groups, system account, current user account
 * Check the users have access permission to the file don't voilate the following rules:
 *        1. no user other than local administrators group, system account, and pwd user have write permission on the file
 *        2. sshd account can only have read permission
 * Returns 0 on success and -1 on failure
 */
int
check_secure_file_permission(const char *input_path, struct passwd * pw)

You need to check that permissions are correct:

  • On the user's home directory (C:\Users\john.doe)
  • On the .ssh directory (C:\Users\john.doe\.ssh)
  • And on the authorized_keys file (C:\Users\john.doe\.ssh\authorized_keys).

Reference:

[1] https://askubuntu.com/questions/1078884/key-rejection-when-do-ssh

Share:
20,959

Related videos on Youtube

Technext
Author by

Technext

Updated on September 18, 2022

Comments

  • Technext
    Technext over 1 year

    I am trying to scp from Bitbucket pipeline wto Windows Server 2016. The Windows server has Win32-OpenSSH installed.

    Command output:

    + scp -v sample.conf [email protected]:/C:/Users/john.doe
    Executing: program /usr/bin/ssh host xx.yyy.zzz.xyz, user john.doe, command scp -v -d -t /C:/Users/john.doe
    OpenSSH_7.7p1, LibreSSL 2.7.4
    debug1: Reading configuration data /home/gradle/.ssh/config
    debug1: Reading configuration data /etc/ssh/ssh_config
    debug1: Connecting to xx.yyy.zzz.xyz [xx.yyy.zzz.xyz] port 22.
    debug1: Connection established.
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/gradle/.ssh/id_pipelines type -1
    debug1: key_load_public: No such file or directory
    debug1: identity file /home/gradle/.ssh/id_pipelines-cert type -1
    debug1: Local version string SSH-2.0-OpenSSH_7.7
    debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_7.7
    debug1: match: OpenSSH_for_Windows_7.7 pat OpenSSH* compat 0x04000000
    debug1: Authenticating to xx.yyy.zzz.xyz:22 as 'john.doe'
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: algorithm: curve25519-sha256
    debug1: kex: host key algorithm: rsa-sha2-512
    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: Server host key: ssh-rsa SHA256:wkXf3e9jgd5W/QY/LwBF41XgeJIC/wLZBeavZI/xYM
    debug1: Host 'xx.yyy.zzz.xyz' is known and matches the RSA host key.
    debug1: Found key in /home/gradle/.ssh/known_hosts:3
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: rekey after 134217728 blocks
    debug1: SSH2_MSG_EXT_INFO received
    debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: publickey
    debug1: Trying private key: /home/gradle/.ssh/id_pipelines
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: keyboard-interactive
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: Next authentication method: password
    debug1: read_passphrase: can't open /dev/tty: No such device or address
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    Permission denied, please try again.
    debug1: read_passphrase: can't open /dev/tty: No such device or address
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    Permission denied, please try again.
    debug1: read_passphrase: can't open /dev/tty: No such device or address
    debug1: Authentications that can continue: publickey,password,keyboard-interactive
    debug1: No more authentication methods to try.
    [email protected]: Permission denied (publickey,password,keyboard-interactive).
    lost connection
    

    Uncommented lines in C:\ProgramData\ssh\sshd_config

    Port 22
    PubkeyAuthentication yes
    AuthorizedKeysFile  .ssh/authorized_keys
    PasswordAuthentication yes
    PermitEmptyPasswords no
    Subsystem   sftp    sftp-server.exe
    

    On Windows server, public key is present in C:\Users\john.doe\.ssh\authorized_keys

    I am just not sure what's wrong with the configuration. Any idea?

  • Technext
    Technext over 5 years
    That exactly was the issue and it happened because i was trying scp with two accounts (mine and a build user's a/c). Since i was able to login remotely using either of these accounts and since both have admin rights on the Windows server, i accidentally ended up modifying my authorized_keys file using the build user's account while troubleshooting. Never thought i would have messed up things like this on Windows. Now i realize permissions matter on Windows as well as far as SSH is concerned. Thank you for pasting the comment from w32-sshfileperm.c file Marcelo! That really helped. :)