参考書で勉強をしていて`rails new scaffold_app -d PostgreSQL`のコマンドを実行したところ、

```

    reate  README.md
          create  Rakefile
          create  .ruby-version
          create  config.ru
          create  .gitignore
          create  Gemfile
             run  git init from "."
    /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/actions.rb:260: warning: Insecure world writable dir /home/tarou/.rbenv/versions/2.5.1 in PATH, mode 040777
    error: chmod on /mnt/c/Code1/scaffold_app/.git/config.lock failed: Operation not permitted
    fatal: could not set 'core.filemode' to 'false'
          create  package.json
          create  app
          create  app/assets/config/manifest.js
          create  app/assets/javascripts/application.js
          create  app/assets/javascripts/cable.js
          create  app/assets/stylesheets/application.css
          create  app/channels/application_cable/channel.rb
          create  app/channels/application_cable/connection.rb
          create  app/controllers/application_controller.rb
          create  app/helpers/application_helper.rb
          create  app/jobs/application_job.rb
          create  app/mailers/application_mailer.rb
          create  app/models/application_record.rb
          create  app/views/layouts/application.html.erb
          create  app/views/layouts/mailer.html.erb
          create  app/views/layouts/mailer.text.erb
          create  app/assets/images/.keep
          create  app/assets/javascripts/channels
          create  app/assets/javascripts/channels/.keep
          create  app/controllers/concerns/.keep
          create  app/models/concerns/.keep
          create  bin
          create  bin/bundle
          create  bin/rails
          create  bin/rake
          create  bin/setup
          create  bin/update
          create  bin/yarn
    Traceback (most recent call last):
            31: from /home/tarou/.rbenv/versions/2.5.1/bin/rails:23:in `<main>'
            30: from /home/tarou/.rbenv/versions/2.5.1/bin/rails:23:in `load'
            29: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/exe/rails:10:in `<top (required)>'
            28: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            27: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:54:in `require'
            26: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/cli.rb:18:in `<top (required)>'
            25: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/command.rb:46:in `invoke'
            24: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/command/base.rb:65:in `perform'
            23: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
            22: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
            21: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
            20: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/commands/application/application_command.rb:26:in `perform'
            19: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
            18: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/group.rb:232:in `dispatch'
            17: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `invoke_all'
            16: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `map'
            15: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `each'
            14: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:133:in `block in invoke_all'
            13: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
            12: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
            11: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/rails/app/app_generator.rb:305:in `create_bin_files'
            10: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/app_base.rb:159:in `build'
             9: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/rails/app/app_generator.rb:94:in `bin'
             8: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/railties-5.2.1/lib/rails/generators/rails/app/app_generator.rb:19:in `chmod'
             7: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/thor-0.20.3/lib/thor/actions/file_manipulation.rb:154:in `chmod'
             6: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:939:in `chmod_R'
             5: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:939:in `each'
             4: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:940:in `block in chmod_R'
             3: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1370:in `preorder_traverse'
             2: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:942:in `block (2 levels) in chmod_R'
             1: from /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1243:in `chmod'
    /home/tarou/.rbenv/versions/2.5.1/lib/ruby/2.5.0/fileutils.rb:1243:in `chmod': Operation not permitted @ apply2files - /mnt/c/Code1/scaffold_app/bin (Errno::EPERM)
    
    
```

というような表示が出てきて作成されないファイルがあり、困っています。

  * ruby 2.5.1
  * rails 5.2.1
  * wsl経由のUbuntu
  * windowsのバージョン 1903

を使っています。  
色々調べてみたのですが自分では解決できないので質問させて頂きました。ご教授願います。

**< 追記>**  
どうやらファイルのパーミッションに関するエラーなのではないかと現在考えているのですが、そこからどうしたらよいか途方に暮れています。  
scaffold_appの権限がrootになっておりそこをユーザー名に変更したらよいのかと思い、

```

    sudo chown -R tarou scaffold_app
    
```

を実行したのですが権限が変更されないです。どうしたらよいのでしょうか。  
以下がファイルのパーミッションになります。

```

    total 0
    drwxrwxrwx 1 root root 512 Nov  7 02:21 ./
    drwxrwxrwx 1 root root 512 Nov  7 01:24 ../
    drwxrwxrwx 1 root root 512 Nov  7 02:21 scaffold_app/
    
```
CC BY-SA 4.0
2019-11-06T14:13:12.647
60298
2023-03-11T14:29:23.273
2019-11-06T17:32:20.557
36506
36506
question
ruby-on-rails wsl
chmod Operation not permitted　というエラーについて
エラーに出ているパス(`/mnt/c`)は恐らくWSL環境からWindowsのファイルシステムを参照しているかと思いますが、`chmod`
等でパーミッション(アクセス権限)を操作するには、メタデータを有効にした状態でマウントする必要があるようです。

`metadata` オプションを付けてドライブをマウント

```

    $ sudo umount /mnt/c
    $ sudo mount -t drvfs C: /mnt/c -o metadata
    
```

なお、WSL build 17093
以降であれば、[設定ファイルに記述しておく](https://qiita.com/remin/items/a726128ab388cb73d9ee)ことでオプションを恒久化する方法もあるようです。

参考:

  * [PHP chmod(): Operation not permitted · Issue #3172 · microsoft/WSL](https://github.com/Microsoft/WSL/issues/3172)
  * [Chmod/Chown WSL Improvements | Windows Command Line](https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/)
  * [WSLからマウントしたWindowsのドライブでchmodしたい - Qiita](https://qiita.com/remin/items/a726128ab388cb73d9ee)
CC BY-SA 4.0
2019-11-06T17:33:01.650
60299
2019-11-06T17:33:01.650
2020-06-17T08:14:45.997
-1
3060
60298
answer
リンク切れしてたので同様の内容を貼っておきます

恒常化について  
<https://rdrgn.hatenablog.com/entry/2018/05/18/000000>

補足 /etc/wsl.conf 等々のある場所  
<https://learn.microsoft.com/ja-jp/windows/wsl/wsl-config>
CC BY-SA 4.0
2023-03-11T14:27:03.523
94132
2023-03-11T14:29:23.273
2023-03-11T14:29:23.273
57485
57485
60298
answer