ルート以外のユーザーにはSSH経由で接続できません。

ルート以外のユーザーにはSSH経由で接続できません。

SSHを使用してローカルネットワーク上のサーバーに接続しようとしてログインできるようにしたいが(明確なセキュリティ目的のために)ログインすることstormはできません。root.pubキーを次の場所にコピーしました。.ssh/authorized_keys

この /etc/ssh/sshd_config を使用すると、次のようになります。

PermitRootLogin no
[...]
Match Address 192.168.1.*,127.0.0.1
   PermitRootLogin yes

私は得る:

$ ssh root@ip
Enter passphrase for key 'PATH_OF_THE_KEY'
$ ssh storm@ip
Permission denied (publickey).

最後に、次の新しい行を追加します。

AllowUsers stormまたはAllowUsers storm root

私は得る:

$ ssh root@ip
Permission denied (publickey).
$ ssh storm@ip
Permission denied (publickey).

ブロックをコメントアウトしても、Match Addressroot とユーザーはブロックされます。誰でも私を助けることができますか?


編集:Stormユーザーへのすべての失敗した接続の履歴

localhost sshd[698]: Invalid user storm from 192.168.1.11
localhost sshd[443]: input_userauth_request: invalid user storm [preauth]
localhost sshd[698]: Connection closed by 192.168.1.11 [preauth]

許可されていないパスワード:

PasswordAuthentication no

ssh -v root@ipssh -v storm@ip同じ出力を提供しますAllowUsers storm

OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.33 [192.168.1.33] port XXXX.
debug1: Connection established.
debug1: identity file /home/storm/.ssh/id_rsa type -1
debug1: identity file /home/storm/.ssh/id_rsa-cert type -1
debug1: identity file /home/storm/.ssh/id_dsa type -1
debug1: identity file /home/storm/.ssh/id_dsa-cert type -1
debug1: identity file /home/storm/.ssh/id_ecdsa type 3
debug1: identity file /home/storm/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/storm/.ssh/id_ed25519 type -1
debug1: identity file /home/storm/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2.3
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.1
debug1: match: OpenSSH_7.1 pat OpenSSH* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr [email protected] none
debug1: kex: client->server aes128-ctr [email protected] none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA XX:XX:XX:XX:XX:XX:XX:XX
debug1: Host '[192.168.1.33]:XXXX' is known and matches the ECDSA host key.
debug1: Found key in /home/storm/.ssh/known_hosts:1
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/storm/.ssh/id_rsa
debug1: Trying private key: /home/storm/.ssh/id_dsa
debug1: Offering ECDSA public key: /home/storm/.ssh/id_ecdsa
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/storm/.ssh/id_ed25519
debug1: No more authentication methods to try.
Permission denied (publickey).

編集2:

drwx------  2 root root 4096 19 sept. 15:47 .ssh
-r-------- 1 root root  236 19 sept. 15:47 authorized_keys

編集3:

職場で! Brandon Xavierに感謝します。各ユーザー(サーバー側)が独自の.sshディレクトリを持っている必要があることを理解していません。これは確かに後で検討したロジックです。


しかし、今はStorm(私が望むもの)としてログインできますが、もはやrootとして直接ログインすることはできません。

どちらにも、正しい所有者/権限と同じ公開鍵を持つ.sshディレクトリ、ファイルがrootあります。 SSHDプロファイルには常にブロックが付属しています。ルートアクセスを防ぐにはどうすればよいですか?stormauthorized_keysauthorized_keysMatch

ベストアンサー1

.sshその下のすべてのアイテムはユーザーが所有しなければなりません(この場合は「storm」)、ユーザーのみが権限を持っている必要があります。chown -R storm ~storm/.ssh; chmod 700 ~storm/.ssh;chmod 600 ~storm/.ssh/authorized_keysこれで問題が解決します。

もしコンソールにログインできる人を制御し、パスワードを無効にし、キーを使用してルートログインのみを許可することで、ブロックとディレクティブを削除できますMatchAllowUsers

PasswordAuthentication no
PermitRootLogin without-password

コンソールにアクセスできるかどうかをテストしてください。 。 。もしかして。

おすすめ記事