1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【EC2】RHEL9以降パスワード認証でSSH接続がいつものようにできなくなっていた件

Last updated at Posted at 2025-05-02

Qiita 初投稿です!

今日は AWS EC2 上で RHEL 9 をパスワード認証でssh接続するために自分の知っている方法で設定して接続をしてみるも「接続できない!?」という事象にハマりましたので、その原因と解決策を記事にしました!


ハマったこと

新しく作成したユーザーでパスワード認証ログインしようとして、下記の設定をしても、なぜか繋がらない…

/etc/ssh/sshd_config を編集

#Banner none
# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server
# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
PasswordAuthentication no

PasswordAuthentication noyes にして、サービスを再起動

systemctl restart sshd.service

teratermでパスワード認証によるssh接続を試しましたが失敗しました、、

投稿用.png

原因はこれでした

/etc/ssh/sshd_config.dの配下に怪しいファイルがありました。

 ll /etc/ssh/sshd_config.d*
total 8
-rw-------. 1 root root  26 May  2 15:43 50-cloud-init.conf
-rw-------. 1 root root 719 Jan  5  2024 50-redhat.conf

50-cloud-init.conf の中身を確認してみるとPasswordAuthentication noがありました。
これをyesに編集すれば解決しそうですね!

# cat /etc/ssh/sshd_config.d/50-cloud-init.conf
PasswordAuthentication no

対処方法

以下の手順で問題を解決しました!

50-cloud-init.conf の内容を yes に変更しサービスを再起動。

vi /etc/ssh/sshd_config.d/50-cloud-init.conf
PasswordAuthentication yes

その結果、無事にパスワード認証で SSH 接続できるようになりました。

タイトルなし.png


まとめ

RHEL 9 の AMI では、/etc/ssh/sshd_config.d/50-cloud-init.confcloud-init により自動生成されており、こちらの設定が優先されます。

本事象は RHEL 9 系の AMI を利用する際に発生する可能性があるため、参考になれば幸いです。


以上、SSH パスワード認証が無効だった原因と対処方法の紹介でした。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?