web-dev-qa-db-ja.com

Synology DSM 5で他の(非root)ユーザーとしてパスワードなし(パスワードなし)でSSH

パスワードなしで(公開キー認証)、Synologyディスクステーションにsshしようとしていますが、非rootです。

パスワードなしでrootとしてsshしようとすると、うまくいきます。別のユーザーがまったく同じ手順を実行しても機能しません。常にパスワードを要求します(また、パスワードの使用も機能します)。

私はこのためにそこにあるすべてのガイドに従ってきましたが、それらはすべて新しい5.0バージョンではなく、DSM 4.xのすべてだと思います。

SSHデバッグログ

-vvvフラグで試したときのデバッグログは次のとおりです。

aether@aether-desktop:~$ ssh -vvv [email protected]
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: [email protected],[email protected],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: [email protected],[email protected],ssh-rsa,[email protected],[email protected],[email protected],[email protected],[email protected],ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,[email protected],[email protected],aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,[email protected]
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-md5,hmac-sha1,[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected],zlib
debug2: kex_parse_kexinit: none,[email protected],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,[email protected]
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,[email protected]
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,[email protected],hmac-ripemd160,[email protected],hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,[email protected]
debug2: kex_parse_kexinit: none,[email protected]
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
[email protected]'s password: 

助けてくれてありがとう。

これまでに試したこと

  • / etc/ssh/sshd_config(RSAAuthentication、PubkeyAuthentication、AuthorizedKeysFile)を確認します。
  • .ssh/*権限と所有権を確認してください。いくつかの組み合わせを試してみました。
  • 〜/ .profileのHOME varを確認してください。
  • Synoservicectl --restart sshdおよびNAS全体を再起動することにより、sshdを再起動しました。
24
Vlad A Ionescu

同じ問題がありました。 「/ usr/syno/sbin/sshd -d」を使用してDiskStationでデバッグモードでsshdのインスタンスを実行し、次に「ssh user @ DiskSation -vvv」を使用してそれに接続し、サーバーでデバッグ情報を取得します。

…….

debug1:temporary_use_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」のような実際のユーザー名に置き換えます。

最後に、問題は解決されました!

50
user334026

ホームディレクトリを755にchmodする必要があります(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
16
spuriousdata

.sshとauthorized_keysの権限が正しく設定されているので、ホームディレクトリ(/home/aether/)への権限が正しく設定されていることを確認してください(chmod 755 /home/aether/)。

デフォルトのアクセス許可(711)でログインできず、アクセス許可を変更した後、機能しました。

乾杯ステファン

5
Stephan

ここでdsm 6.0と同じ問題、Synologyフォーラムの this thread のおかげで解決

ユーザーの自宅へのアクセス許可が多すぎるようです¿?¿??¿¿?

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

...そして今はうまくいきます!

2
Gonzalo Cao

私は同じ問題を抱えており、上記のすべてを二重および三重にチェックしましたが、それでも機能しませんでした。最後に、/ home/nonrootuserディレクトリーがないため、sshデーモンが誤った場所でauthorized_keysファイルを探していることがわかりました。

パスを作成するか、シンボリックリンクを作成する必要があります(これらの2つのオプションは機能しませんでした)。または、最終的に機能したのは、sshd_configファイルに次の2行を追加することです。

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

このようにして、クライアントからssh-copy-idを介して追加するキーが、サーバー(synology)が非rootユーザーの接続を確立するために提供しているものと同じであることを確認します。

2
user334008

私も同じ問題を抱えていました。私のauthorized_keys、file home、および.sshディレクトリに適切な権限を設定した後も、DiskstationにSSHで接続できませんでした。

techanic.net の情報を読んだ後、/etc/passwdファイルにlogin Shellも設定する必要があることを発見しました。デフォルトでは/sbin/nologinに設定されていました。 /bin/shに変更した後、DiskstationにSSHで接続できました。

1

それはその質問に非常に似ています:

https://stackoverflow.com/questions/12839106/scp-between-2-remote-hosts-without-password/12945060#1294506

.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の内容を確認してください。これにより、非ルートにいくつかの制限が課される可能性があります。念のため。このリンクは、RHELの場合のPAMについて説明しています。役立つ場合があります: https://access.redhat.com/site/documentation/en-US/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を好きではないのですか?

1
Grzegorz

5.0ではなくDSM 5.1で同じ問題が発生しました。リストされている解決策のどれも問題を解決しませんでした。私の場合、/var/services/homes/<user>/.ssh/authorized_keysは正しくありませんでした。次を実行すると問題が解決しました

chmod 600 /var/servieces/homes/<user>/.ssh/authorized_keys
0