0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[備忘録] WSL関連のTips

Last updated at Posted at 2025-03-24

まえおき

WSL関連のTipsを記載していく。

同一ディストリビューションの複製

  1. 複製したいディストリビューション名を取得

    PowerShellにて以下のコマンドを実行する。

    wsl -l -v
    

    以下のように出力される。

      NAME                   STATE           VERSION
    * Ubuntu-22.04           Running         2
      Ubuntu-24.04           Running         2
      ...
    
  2. ディストリビューションのエクスポート

    PowerShellにて以下のコマンドを実行する。

    wsl --export Ubuntu-24.04 <任意の名称>.tar
    
  3. ディストリビューションのインポート

    PowerShellにて以下のコマンドを実行する。

    wsl --import <任意の名称(*1)> <ディストリビューションのデータを置く場所のパス> <エクスポートしたディストリビューションのパス>
    

    *1: wsl -l -vを実行したときにNAMEに表示される。

Ubuntu起動時のログインユーザを作成したユーザにする

起動時のログインユーザがrootになってしまう場合の対処法になります。

  1. wsl.conf書き換え

    Ubuntuにて以下のコマンドを実行する。

    nano /etc/wsl.conf
    

    以下の項目を追記する。

    + [user]
    + default=<ログインしたいユーザ名>
    
  2. WSL再起動

    PowerShellにて以下のコマンドを実行する。

    wsl --shutdown <ディストリビューション名>
    

sudo使用時のパスワード無効化

  1. sudoers書き換え

    Ubuntuにて以下のコマンドを実行する。

    sudo visudo
    

    以下の項目を追記する。
    # Allow members of group sudo to execute any commandの中に書き込めばよいかと。

    + <ユーザ名> ALL=(ALL) NOPASSWD: ALL
    
  2. シェル再読み込み

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?