LoginSignup
0
0

RHEL9でrootユーザのパスワード認証有効化ができない...

Last updated at Posted at 2024-05-25

近況

最近は投資信託の調子がよく(?)、毎朝評価額が増えているのを見てニマニマしています。
ちなみに買っている銘柄は学生時代(旧NISA)から「たわらノーロード 先進国株式」です。

最近はアメリカハイテク株をメインとする「iFreeNEXT FANG+インデックス」も少し買ったりしています。

今回の環境

AWSのEC2にRHEL9を立てて、rootユーザーでのパスワード認証を設定する際に「設定間違っていないはずなのになんかできないなあ。。。」っていうのが、ことの発端でした。

使ったAMIは、クイックスタートAMIである「ami-0014871499315f25a」です。
一応バージョンを調べましたが、9.3でした。

$ cat /etc/redhat-release
Red Hat Enterprise Linux release 9.3 (Plow)

いろいろ調べてみましたが、 RHEL9から「rootユーザーのパスワード認証有効化」に関しては、RHEL8以前とは違っているようでした。


ここでいう手順①が、以前のバージョンでは要らなかったはずです。
echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config.d/01-permitrootlogin.conf

設定していく

EC2への接続

①Desktopにキーペアファイルを置く

②ターミナルでデスクトップに移動する
cd Desktop

③以下コマンドでキーペアファイルの権限を変更する。
chmod 600 RHEL-test.pem
※777で設定すると、権限を与えすぎ!と怒られて接続できませんでした。

④以下コマンドを実行し接続
ssh -i RHEL-test.pem ec2-user@[EC2のIPアドレス]

パスワード認証の有効化設定を入れていく ※RHEL8以前と同様

①rootユーザにスイッチする
sudo su

②sshd_configの確認
cat /etc/ssh/sshd_config

※ここで以下の設定値を確認しておく(上から11行目くらい)
Include /etc/ssh/sshd_config.d/*.conf

③パスワード認証有効化
vi /etc/ssh/sshd_config

【変更箇所】
#PasswordAuthentication yes
→PasswordAuthentication yes

#PermitRootLogin prohibit-password
→PermitRootLogin yes

④sshdサービスリロード
systemctl reload sshd

⑤rootユーザのパスワード変更
passwd
新しいパスワード:P@ssw0rd

※P@ssw0rdはBad password!と怒られますが、設定はできます。

RHEL8以前はこの設定だけで、いけた。
けど、ログインを試すと、接続できません。

macだとこんな感じ
root@x.x.x.x: Permission denied (publickey,gssapi-keyex,gssapi-with-mic).

Windowsだとこんな感じです

image.png

image.png

RHEL9からの変更点を追加設定していく

さっきsshd_config内にあった「Include /etc/ssh/sshd_config.d/*.conf」が影響しているといった内容の記事をいくつか見かけました。

要するに、「/etc/ssh/sshd_config.dの中にxxx.confを作って、そこで設定してくださいね。」という内容でした。
なので、冒頭のRedHatの参考URLに記載の以下コマンドを実行する必要がある、ということでした。

echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config.d/01-permitrootlogin.conf

早速実行したのち、再度rootでのパスワード認証ができるか試します。
が、やっぱり失敗しちゃいます。

ここで、「/etc/ssh/sshd_config.d」の中のファイルを確認すると、以下のファイルがありました。

・01-permitrootlogin.conf(今さっき作成したファイル)
・50-cloud-init.conf(ナニコレ)
・50-redhat.conf(ナニコレ)

中身をそれぞれ確認するとこんな感じでした。

cat 01-permitrootlogin.conf
PermitRootLogin yes

cat 50-cloud-init.conf
PasswordAuthentication no

cat 50-redhat.conf

# This system is following system-wide crypto policy. The changes to
# crypto properties (Ciphers, MACs, ...) will not have any effect in
# this or following included files. To override some configuration option,
# write it before this block or include it before this file.
# Please, see manual pages for update-crypto-policies(8) and sshd_config(5).
Include /etc/crypto-policies/back-ends/opensshserver.config

SyslogFacility AUTHPRIV

ChallengeResponseAuthentication no

GSSAPIAuthentication yes
GSSAPICleanupCredentials no

UsePAM yes

X11Forwarding yes

# It is recommended to use pam_motd in /etc/pam.d/sshd instead of PrintMotd,
# as it is more configurable and versatile than the built-in version.
PrintMotd no

中身を見ると、明らかにこの「50-cloud-init.conf」が原因となっていました。
これを以下のように変更したら、無事rootでパスワード認証ができ、入れました。

PasswordAuthentication no
→PasswordAuthentication yes

※実際には、トラブル調査を手伝ってくれた先輩が、コレやん!と解決してくれました。

僕ももっとLinuxをしっかり勉強しなければなあと強く感じました。

さいごに

今回の作業で、RHEL7と9の初期設定を行いましたが、こんなところで躓くとは思ってなかったです。
今後、誰かが引っかかった時に参考となれば幸いです。
それではまたどこかで。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0