5
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?

More than 1 year has passed since last update.

IBM Cloud: VSI for VPC環境でログインできなくなった環境をchroot jail環境から修正する方法

Last updated at Posted at 2022-10-29

IBM Cloudには、デフォルトではrootユーザーに公開鍵暗号方式でSSHログインできるように初期構成されているが、一般的には構築・運用の途中で、

  • /etc/ssh/sshd_configの設定間違い
  • SELinuxの設定間違い
  • OS Firewallの設定間違い
  • PAMの設定間違い

などによりSSHでログインできなくなってしまったとか、rootユーザーにログインできなくなったケースなどの際に回復できる手順があることが望ましい。今回は、rootパスワードがわからなくなって環境を操作できなかったという想定で、Red Hat Enterprise Linux 8.4のboot時にカーネルオプションをVNCから編集することにより、rootパスワードをリセットする方法を紹介する。基本はこの方法を踏襲すれば良い。

1. VNCコンソールを起動する。

image.png

2. VNCコンソールを起動したままOSを再起動する。

image.png

3. GRUBの編集画面に入る

VNCコンソールを起動したまま、OSを再起動する。すると、以下のようなGRUBの画面が現れる。GRUBはデフォルトでは1秒程度で抜けてしまうので、リブートしたらすぐに下矢印キーを連打しておくと良い。eを押下して編集画面に入る。
image.png

4. カーネルコマンドの編集

linuxと書かれている行に移動する。Ctrl + eで行末に移動できる。

  • 以下のようにrd.breakを追加してCtrl + xを押下すれば良いはずだが、これだとEnding clean mountの箇所で止まってしまった。image.pngimage.png
  • 回避策として、以下のように文末にrd.breakを追加するだけでなく、console=tty0 console=ttyS0,115200n8という箇所も削除して、Ctrl + xを押下する。参考記事image.pngimage.png

5. 以下のコマンドを実行してパスワードをリセットする

/sysrootはread onlyでマウントされているので、読み書きができるように再マウント
switch_root:/# mount -o remount,rw /sysroot
/sysrootにchroot
switch_root:/#  chroot /sysroot
変更・復元作業(rootパスワードの変更など)
sh-4.4# passwd
sh-4.4# touch /.autorelabel

image.png

あとは、OSの再起動をすれば良い。

5
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
5
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?