SSH public key auth doesn't work

Don't miss a thing. Post your questions and discussion about other uncategorized NAS features here.
Post Reply
maciekish
Starting out
Posts: 19
Joined: Mon Sep 06, 2010 2:42 pm

SSH public key auth doesn't work

Post by maciekish »

Hi,
I copied my /root/.ssh/id_rsa.pub key to ~/.ssh/authorized_keys on the qnap but its not working (I'm asked to provide my password). If i provide the qnap user password, it connects.

I have seen https://wiki.qnap.com/wiki/SSH:_How_To_ ... rized_Keys and used this before between other non-qnap-hosts just fine.

The client trying to connect to the Qnap:

Code: Select all

debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
The qnap admin .ssh folder:

Code: Select all

[~] # ls -lah .ssh/
total 44
drwx------    2 admin    administ    4.0K May  8 12:55 ./
drwxr-xr-x   39 admin    administ   12.0K May  8 12:40 ../
-rw-------    1 admin    administ    1.1K May  8 12:55 authorized_keys
lrwxrwxrwx    1 admin    administ      16 May  2 23:19 id_rsa -> ssh_host_rsa_key
lrwxrwxrwx    1 admin    administ      20 May  2 23:19 id_rsa.pub -> ssh_host_rsa_key.pub
-rw-------    1 admin    administ     668 May  2 22:28 ssh_host_dsa_key
-rw-r--r--    1 admin    administ     605 May  2 22:28 ssh_host_dsa_key.pub
-rw-------    1 admin    administ    1.6K May  2 22:28 ssh_host_rsa_key
-rw-r--r--    1 admin    administ     397 May  2 22:28 ssh_host_rsa_key.pub
-rw-r--r--    1 admin    administ     224 May  8 11:59 sshd_config
-rw-r--r--    1 admin    administ      27 May  8 11:59 sshd_user_config
ashakeandfrys
New here
Posts: 2
Joined: Mon May 08, 2017 8:17 pm

Re: SSH public key auth doesn't work

Post by ashakeandfrys »

I noticed the same thing after the most recent update..
maciekish
Starting out
Posts: 19
Joined: Mon Sep 06, 2010 2:42 pm

Re: SSH public key auth doesn't work

Post by maciekish »

Wtf qnap. We paid you a lot of money you know? This is the second major issue i hit in the first week. I think ill go back to a regular Ubuntu box next time an upgrade is due :(
User avatar
OneCD
Guru
Posts: 12161
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: SSH public key auth doesn't work

Post by OneCD »

To gather some more info, try this from your client machine:

Code: Select all

ssh -vvv admin@wocky
... and check the lines in this area. Specifically, the result of the highlighted line:
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/not/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 279
debug2: input_userauth_pk_ok: fp 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff
debug3: sign_and_send_pubkey: RSA 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff
debug1: Authentication succeeded (publickey).
Authenticated to wocky ([10.0.0.2]:22).

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
maciekish
Starting out
Posts: 19
Joined: Mon Sep 06, 2010 2:42 pm

Re: SSH public key auth doesn't work

Post by maciekish »

% ssh admin@redacted.tld -vvv ~ ams
OpenSSH_7.2p2 Ubuntu-4ubuntu2.1, OpenSSL 1.0.2g 1 Mar 2016
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: resolving "redacted.tld" port 22
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to redacted.tld [xx.xx.xx.xx] port 22.
debug1: Connection established.
debug1: identity file /home/redacted/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/redacted/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.3
debug1: match: OpenSSH_7.3 pat OpenSSH* compat 0x04000000
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to redacted.tld:22 as 'admin'
debug3: hostkeys_foreach: reading file "/home/redacted/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/redacted/.ssh/known_hosts:3
debug3: load_hostkeys: loaded 1 keys from redacted.tld
debug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa
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: KEX algorithms: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: ssh-rsa-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,3des-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: rsa-sha2-512
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: ssh-rsa SHA256:HnSTkraDPrYaLVYRD0vVlhR7OQIjnH05EQRjUyi5vuM
debug3: hostkeys_foreach: reading file "/home/redacted/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/redacted/.ssh/known_hosts:3
debug3: load_hostkeys: loaded 1 keys from redacted.tld
debug3: hostkeys_foreach: reading file "/home/redacted/.ssh/known_hosts"
debug3: record_hostkey: found key type RSA in file /home/redacted/.ssh/known_hosts:4
debug3: load_hostkeys: loaded 1 keys from xx.xx.xx.xx
debug1: Host 'redacted.tld' is known and matches the RSA host key.
debug1: Found key in /home/redacted/.ssh/known_hosts:3
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
debug2: set_newkeys: mode 0
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS received
debug2: key: /home/redacted/.ssh/id_rsa (0x7f292dde1e20)
debug2: key: /home/redacted/.ssh/id_dsa ((nil))
debug2: key: /home/redacted/.ssh/id_ecdsa ((nil))
debug2: key: /home/redacted/.ssh/id_ed25519 ((nil))
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 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: start over, passed a different list publickey,password,keyboard-interactive
debug3: preferred gssapi-keyex,gssapi-with-mic,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 RSA public key: /home/redacted/.ssh/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,password,keyboard-interactive
debug1: Trying private key: /home/redacted/.ssh/id_dsa
debug3: no such identity: /home/redacted/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/redacted/.ssh/id_ecdsa
debug3: no such identity: /home/redacted/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /home/redacted/.ssh/id_ed25519
debug3: no such identity: /home/redacted/.ssh/id_ed25519: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug3: send packet: type 50
debug2: we sent a keyboard-interactive packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred:
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
crubel
First post
Posts: 1
Joined: Thu May 18, 2017 10:48 pm

Re: SSH public key auth doesn't work

Post by crubel »

I am adding that I have 3 qnap systems at work that we have been using public key auth for years, the latest suggested
updates to 4.2.5 or 4.3.3 due to security recommendations has left us with none of these systems able to be used anymore
in the manner we have been using them since we set them up.

Perhaps someone at QNAP who handles these security updates can actually chime in and let us know what/why
this is no longer working. Ive just wasted 2 days ensuring the configuration is still OK and all our other Unixish
systems here are fine, the qnap systems are the only ones affected after this last update.

You are no longer allowed to ssh into our out of the Qnap systems using public key authentication.
The log file data has no useful information as previously posted by the other party that I could
see other than the required use of of only RSA keys, which has been in place for some time
now I believe.

Any one that can shed some light on this, we would certainly appreciate any helpful information...

Thank you,

crubel
AlastairStevenson
Experience counts
Posts: 2415
Joined: Wed Jan 08, 2014 10:34 pm

Re: SSH public key auth doesn't work

Post by AlastairStevenson »

Perhaps someone at QNAP who handles these security updates can actually chime in and let us know what/why
this is no longer working.
Perhaps it's time to submit a QNAP HelpDesk ticket, if the community itself can't help : https://helpdesk.qnap.com/index.php?/Tickets/Submit
TS-431+ for storage and media and a bunch of IP cams under Surveillance Station. TVS-473 as files backup and QVR Pro.
SynAckFin
New here
Posts: 3
Joined: Mon May 30, 2016 3:17 pm

Re: SSH public key auth doesn't work

Post by SynAckFin »

I think I have found the solution.

Find the real path of the key files:

Code: Select all

$ ssh admin@yourQnap
[~] # readlink -f .ssh/
/mnt/HDA_ROOT/.config/ssh
You then have to look at each component of the path:

Code: Select all

[~] # ls -ld / /mnt /mnt/HDA_ROOT /mnt/HDA_ROOT/.config /mnt/HDA_ROOT/.config/ssh
drwxr-xr-x   22 admin    administ       520 May 20 12:40 //
drwxr-xr-x   11 admin    administ       240 May 20 12:38 /mnt/
drwxr-xr-x   10 admin    administ      4096 May 20 12:38 /mnt/HDA_ROOT/
drwxrwxrwx   39 admin    administ     12288 May 20 12:51 /mnt/HDA_ROOT/.config/
drwx------    2 admin    administ      4096 May 20 12:38 /mnt/HDA_ROOT/.config/ssh/
Note how /mnt/HDA_ROOT/.config/ has write permission for everyone. This is seen as a security hole (and it is) so ssh will ignore any keys stored beyond that point as they may have been compromised. You need to change the permissions to something less permissive.

Code: Select all

[~] # chmod 755 /mnt/HDA_ROOT/.config/
It should now work.
murdochs
Getting the hang of things
Posts: 71
Joined: Tue Feb 23, 2010 8:43 am

Re: SSH public key auth doesn't work

Post by murdochs »

hi, have the same problem, and spent all day trying to fix. I found that if I run the command "chmod 755 /mnt/HDA_ROOT/.config/", (only just found this post now), it does not survive a reboot. After reboot, If I try to ssh to box, I am asked for password. When I chmod to 755, works straight away. Reboot, back to requesting password. How can I make this change permanent please ?
Sean
SynAckFin
New here
Posts: 3
Joined: Mon May 30, 2016 3:17 pm

Re: SSH public key auth doesn't work

Post by SynAckFin »

I've rebooted mine several times now and it survives the reboot.

It might be that one of the services you are running is setting these permissions at startup.
You could try tracking down which one by disabling some of them and seeing it it still happens.
Alternatively you could try adding a crontab to periodically set the permission although the crontab might get rebuilt every reboot which would leave you in the same position.
Post Reply

Return to “Miscellaneous”