
AWS に Ubuntu インスタンスがあります。SSH
ログインを取得した後、コマンドを使用して root パスワードに変更できましたsudo su
。
セキュリティ上の理由から、root パスワードを変更したいと考えました。そこで、次のことを試しました。
root@email:/home/ubuntu# sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
root@email:/home/ubuntu#
パスワードを変更しようとしてもsudo su
、パスワードを求められません
ubuntu@email:~$ sudo su
root@email:/home/ubuntu#
一方、 のみを試みるとsu
、次の 1 つが要求されます。
ubuntu@email:~$ su
Password:
セキュリティを実装したり、パスワードを設定したりするにはどうすればよいですかsudo su
?
以下はsudoers(visudo)の詳細です。
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
答え1
sudoers
ファイル内のこの行
#includedir /etc/sudoers.d
ディレクトリから他のファイルを含めます/etc/sudoers.d/
。行がコメント アウトされているように見えるかもしれませんが、そうではありません。ディレクティブの#includedir
先頭にはがあります#
。これらのインクルードされたファイルの 1 つが でルールを設定しており、NOPASSWD
それが問題の原因となっている可能性があります。
何かを変更する前に、通常のユーザーが有効なパスワードを持っていることを確認してください。この答え:
sudo
パスワードを持っていなくてもパスワードを要求し、空のパスワードは受け入れません。
疑問がある場合は、passwd
通常のユーザーの新しいパスワードを呼び出して設定してください。
このコマンドは、検査する必要があるファイルを通知します。
sudo grep -r NOPASSWD /etc/sudoers.d/
探している行は次のようになります。
ubuntu ALL=(ALL) NOPASSWD:ALL
コメントアウトします(# ubuntu ALL=...
)。比較この答え。