与其他(非root)用户一样,在Synology DSM 5上没有密码(无密码)的SSH


24

我正在尝试不使用密码(公共密钥身份验证)但不以root用户身份登录到Synology Disk Station。

当我尝试以root用户身份登录而不使用密码时,它可以工作。对其他用户执行完全相同的步骤无效。它总是要求输入密码(也可以使用密码)。

我已经按照那里的所有指南进行操作,但是我认为它们全部用于DSM 4.x,而不是用于新的5.0版本。

SSH调试日志

这是我尝试使用-vvv标志时的调试日志:

aether@aether-desktop:~$ ssh -vvv aether@aether-ds.local
OpenSSH_6.2p2 Ubuntu-6ubuntu0.2, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to aether-ds.local [192.168.2.149] port 22.
debug1: Connection established.
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/aether/.ssh/id_rsa" as a RSA1 public key
debug1: identity file /home/aether/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/aether/.ssh/id_rsa-cert type -1
debug1: identity file /home/aether/.ssh/id_dsa type -1
debug1: identity file /home/aether/.ssh/id_dsa-cert type -1
debug1: identity file /home/aether/.ssh/id_ecdsa type -1
debug1: identity file /home/aether/.ssh/id_ecdsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2p2 Ubuntu-6ubuntu0.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1-hpn13v11
debug1: match: OpenSSH_5.8p1-hpn13v11 pat OpenSSH_5*
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "aether-ds.local" from file "/home/aether/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/aether/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: RSA f1:57:47:37:47:d4:5c:cd:a7:a4:5a:9c:a3:e8:1d:13
debug3: load_hostkeys: loading entries for host "aether-ds.local" from file "/home/aether/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/aether/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys
debug3: load_hostkeys: loading entries for host "192.168.2.149" from file "/home/aether/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/aether/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug1: Host 'aether-ds.local' is known and matches the RSA host key.
debug1: Found key in /home/aether/.ssh/known_hosts:1
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/aether/.ssh/id_rsa (0x7f4ee2f47200),
debug2: key: /home/aether/.ssh/id_dsa ((nil)),
debug2: key: /home/aether/.ssh/id_ecdsa ((nil)),
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
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/aether/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/aether/.ssh/id_dsa
debug3: no such identity: /home/aether/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /home/aether/.ssh/id_ecdsa
debug3: no such identity: /home/aether/.ssh/id_ecdsa: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
aether@aether-ds.local's password: 

任何帮助表示赞赏。

到目前为止我尝试过的事情

  • 检查/ etc / ssh / sshd_config(RSAAuthentication,PubkeyAuthentication,AuthorizedKeysFile)。
  • 检查.ssh / *权限和所有权。尝试了几种组合。
  • 在〜/ .profile中检查HOME var。
  • 通过synoservicectl --restart sshd并通过重新启动整个NAS重新启动sshd。

为什么要这样做?使用不受保护的密钥进行公钥身份验证是否足够?
Daniel B

丹尼尔,您好,这正是我要实现的目标,但不适用于非root用户。
Vlad A Ionescu 2014年

您的客户的公钥是否存在于用户 authorized_keys文件中?
Daniel B

是的,我用ssh-copy-id复制了它。它是与root用户完全相同的authorized_keys文件(但具有正确的权限),在root用户时可以使用。
Vlad A Ionescu 2014年

您的帐户现在有密码了吗?根据您的系统的安全策略,如果没有密码的用户可以从日志中禁止。
丹尼尔乙

Answers:


49

我有同样的问题。我在DiskStation上使用“ / usr / syno / sbin / sshd -d”以调试模式运行sshd的实例,然后使用“ ssh user @ DiskSation -vvv”连接到它,并在服务器上获得了调试信息:

......

debug1:临时使用_uid:1026/100(e = 0/0)

debug1:尝试使用公共密钥文件/var/services/homes/user/.ssh/authorized_keys

debug1:fd 5清除O_NONBLOCK

身份验证被拒绝:所有权错误或目录/ volume1 / homes / user的模式

......

我意识到主文件夹也需要正确的权限:

cd /var/services/homes/
chown <username> <username>
chmod 755 <username>

并替换为实际的用户名,例如“ user”。

终于,问题解决了!


2
正如你,跑chmod 755在我的主目录解决了这个对我来说在DSM 6
大卫Pärsson

它始终是获取调试日志的正确解决方案。谢谢!只是一个附加功能:调用/usr/bin/sshd -p 2222(并与连接ssh -p 2222),使其在不同的端口上运行以进行调试-否则,如果您退出ssh deamon,可能会失去访问权限
Alex

16

您需要将主目录更改为755(默认情况下,synology的目录为777)

nas> ls -al
total 28
drwxrwxrwx  6 root     root  4096 2014-07-13 03:00 .
drwxr-xr-x 13 root     root  4096 2014-07-13 03:00 ..
drwxrwxrwx  3 admin    users 4096 2014-07-13 03:00 admin
...
nas> chmod 755 /home/admin
nas> ls -al
total 28
drwxrwxrwx  6 root     root  4096 2014-07-13 03:00 .
drwxr-xr-x 13 root     root  4096 2014-07-13 03:00 ..
drwxr-xr-x  3 admin    users 4096 2014-07-13 03:00 admin

这并不表示chmod 755 /home/admin实际更改了权限。
user20342 2014年

对,是真的。的确如此,我只是将粘贴的示例拼凑在一起,而我错过了。我将编辑答案。
spuriousdata

5

.ssh正确设置了对和的许可权后,只需验证对主目录(/home/aether/)的许可权是否已正确设置(chmod 755 /home/aether/)。

我无法使用默认权限(711)登录,并且在更改权限后可以正常使用。

干杯斯蒂芬


2

我遇到了同样的问题,两次以上都检查了两次,但还是没用。最终,我意识到ssh守护进程在错误的位置查找了authorized_keys文件,因为没有/ home / nonrootuser目录。

您应该创建路径或进行符号链接(这两个选项对我不起作用),或者最终有效的方法是在sshd_config文件中添加这两行:

Match User nonrootuser
AuthorizedKeysFile      /var/services/homes/nonrootuser/.ssh/authorized_keys

这样,您可以确保通过客户端的ssh-copy-id添加的密钥与服务器(synology)提供的用于为非rootuser稳定连接的密钥相同。


2

dsm 6.0在这里也存在同样的问题,这要归功于Synology论坛上的该线程

似乎用户归属权限太宽松了?

chmod 755 /var/services/homes/[username]

...现在可以了!


1

它看起来与该问题非常相似:

/programming/12839106/scp-between-2-remote-hosts-without-password/12945060#12945060

我怀疑您的.ssh目录或文件没有适当的属性。

这是我的:

-rw-r--r--  1 root root   393 Aug 13  2012 if_rsa.pub
-rw-------  1 root root  1675 Aug 13  2012 if_rsa
-rw-r--r--  1 root root   393 Aug 20  2012 id_rsa.pub
-rw-------  1 root root  1675 Aug 20  2012 id_rsa
-rw-------  1 root root  4606 Aug  7  2013 authorized_keys
drwx------  2 root root  4096 Feb 24 09:59 .
-rw-r--r--  1 root root 11354 Mar 25 17:28 known_hosts

另外,请检查其中的内容/etc/pam.d/sshd可能会对非root用户施加一些限制。以防万一。如果使用RHEL,此链接说明了PAM。它可能会有所帮助:https : //access.redhat.com/site/documentation/zh-CN/Red_Hat_Enterprise_Linux/6/html/Managing_Smart_Cards/PAM_Configuration_Files.html

这是该问题显示出丑陋之处的地方:

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/aether/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password

它不接受id_rsa,并继续:

debug1: Trying private key: /home/aether/.ssh/id_dsa
debug1: Trying private key: /home/aether/.ssh/id_ecdsa

它放弃了,并依靠密码

debug1: Next authentication method: password

因此,现在的问题是为什么它不喜欢id_rsa?


您好的Grzegorz,你的.ssh DIR具有烫发700和的.ssh / authorized_keys中具有烫发600
维拉德甲Ionescu的

@VladAlexandruIonescu:我已经更新了我的回复,其中显示了其他属性以及有关PAM的信息,这些信息可能会给您更多的测试领域。
Grzegorz

谢谢,格热哥兹,但仍然没有运气。我已经尝试过与您完全相同的烫发。还浏览了/etc/pam.d/sshd,但是看起来没有什么可以区别root用户:gist.github.com/vlad-alexandru-ionescu/e6a2ee6133c7e9e45273
Vlad A Ionescu 2014年

@VladAlexandruIonescu:是否所有用户都遇到此问题?您写了“给另一个用户”,它可能只表示一个。您可以使用该用户登录名输入腻子,还是先以root用户登录然后输入su?
Grzegorz 2014年

是的,适用于所有非root用户。我可以以任何用户(root或非root)身份ssh / putty。但是,即使我已将客户端的公共密钥添加到服务器上的authorized_keys中,它也会在非root用户时要求输入密码。
Vlad A Ionescu 2014年

1

我有同样的问题。在我的authorized_keys,文件主目录和.ssh目录上设置了正确的权限之后,我仍然无法通过SSH连接到Diskstation。

阅读了techanic.net上的信息后,我发现我还必须在文件中设置登录shell/etc/passwd/sbin/nologin默认设置为。将其更改为/bin/sh我之后,便可以成功地将其SSH连接到Diskstation。


0

我只是在DSM 5.1中遇到了同样的问题,而不是5.0。列出的解决方案均未解决该问题。就我而言,权限/var/services/homes/<user>/.ssh/authorized_keys是不正确的。运行以下命令解决了该问题

chmod 600 /var/servieces/homes/<user>/.ssh/authorized_keys
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.