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

Djangoのsettings.pyがPermission deniedになったけど、chownで解決した話

Posted at

起きたこと

Djangoプロジェクトの settings.py を開こうとしたところ、以下のエラーが発生した。

Permission denied

エディタ(vim / VS Code)から 閲覧すらできない状態。

原因

ファイルの所有者が自分ではなく、root になっていた。

$ ls -l settings.py
-rw-r----- 1 root root  settings.py
  • 所有者:root
  • 自分のユーザー:vboxuser
  • vboxuser には読み取り権限がない
    → そのため Permission エラーが発生していた。

解決方法

chown コマンドで、ファイルの所有者とグループを自分に戻した。

$ sudo chown vboxuser:vboxuser settings.py

コマンドの意味

chown ユーザー名:グループ名 対象ファイル
  • 所有者 → vboxuser
  • 所有グループ → vboxuser

修正後の状態

$ ls -l settings.py
-rw-r--r-- 1 vboxuser vboxuser settings.py

無事にファイルを閲覧・編集できるようになった。

chmodではダメなのか?

一見すると以下でも直りそうに見える。

$ chmod 644 settings.py

しかしこれは 権限(rwx)を変更しているだけ で、

  • 所有者・グループは root のまま
  • 根本原因は解決していない
    →「誰のファイルか」を直すには chown が必要

まとめ

  • Permission denied の原因は ファイルの所有者・グループが自分でないこと
  • chmod は権限変更、chown は所有者変更
0
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
0
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?