2018年5月12日土曜日

WSL の Debian 9 で初期ユーザのパスワードを忘れたら

WSL の Debian 9 では、管理者権限で開いたコンソールから debian.exe を実行し、ログインユーザーを root に変更することが出来ます。Ubuntu の場合は ubuntu.exe で、他のディストリビューションの場合も似たようなネーミングの命令が入っていると思います。

PS C:\WINDOWS\system32> debian help
Launches or configures a linux distribution.

Usage:
    
      - Launches the distro's default behavior. By default, this launches your default shell.

    run 
      - Run the given command line in that distro, using the default configuration.
      - Everything after `run ` is passed to the linux LaunchProcess call.

    config [setting [value]]
      - Configure certain settings for this distro.
      - Settings are any of the following (by default)
        - `--default-user `: Set the default user for this distro to 

    clean
      - Uninstalls the distro. The appx remains on your machine. This can be
        useful for "factory resetting" your instance. This removes the linux
        filesystem from the disk, but not the app from your PC, so you don't
        need to redownload the entire tar.gz again.

    help
      - Print this usage message.
PS C:\WINDOWS\system32> debian config --default-user root
Default UNIX user set to: root

初期ユーザのパスワードを忘れてしまったので、実際に作業してみました。
  1. 管理者として PowerShellかcmdウインドウを開く。
  2. PS> debian config --default-user root でログインユーザを root にする
  3. WSL Debian を開くとログインユーザが root になっているはず。
  4. # passwd firstuser などとしてパスワードを変更する。
  5. WSL Debian を閉じておく。
  6. PS> debian config --default-user firstuser などとしてログインユーザを初期ユーザにする。
  7. WSL Debianを開くとログインユーザが 初期ユーザになっているはず。 sudo su などしてパスワードが新しいものになっているか確認する。
実機の場合はgrubの起動に割り込んでinit=/bin/sh とか追加書きして云々、とかやるパターンですが、これはありがたいですね。

参考記事はこちら。
https://askubuntu.com/questions/772050/reset-the-password-in-linux-bash-in-windows

0 件のコメント: