wslでユーザーのパスワードを忘れてしまった場合のリセット方法

最終更新日:2025‐06-08

Claude Codeを試そうと思い、久しぶりWSLのターミナルからsudo updateを実行しようと思ったところ、ユーザーのパスワードを忘れてしまい、リセットした話です。

まずは、Windowsのコマンドプロンプトを管理者モードで実行します。
そして、ディストリビューションの一覧を表示します。

wsl --list
Python

以下のように応答があります。

Ubuntu-22.04 (既定)
docker-desktop
docker-desktop-data
Python

こんな風に結果が返却されるので、以下のようにコマンドを打ちます。
--distoribution 以降は 先ほどwsl --listで調べたディストリビューション名を入力します。

wsl --user root --distribution Ubuntu-22.04
Python

以下のように応答があります。

Welcome to Ubuntu 22.04.3 LTS (GNU/Linux 5.15.146.1-microsoft-standard-WSL2 x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

 * Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
   just raised the bar for easy, resilient and secure K8s cluster deployment.

   https://ubuntu.com/engage/secure-kubernetes-at-the-edge

This message is shown once a day. To disable it please create the
/root/.hushlogin file.
Python

そうしたら、rootユーザーとしてログインできているので、該当ユーザーのパスワードを変更します。

passwd hogepiyo
Python

新しいパスワードを聞かれるので入力してあげます。

以上です👀

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です