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?

インターン先でとても役に立ったchmodについてまとめた

Posted at

背景

インターン先でGCPのVM上でLLM学習環境を触っていたとき、他のメンバー作成ディレクトリ内のファイルをcpしようとしてPermission deniedになったことがある。
その時はどのように直せばよいか分からなかったので他のメンバーに聞いたところ、どうやらchmodというものがあるんだと知った。

TL;DR

  • いつ使う?:ファイルやディレクトリの「読み・書き・実行」権限を、誰(所有者/グループ/その他)に与えるか外すかを変更したいとき
  • 役割:u/g/o(所有者/グループ/その他)
  • 権限:r=4, w=2, x=1(足し算でどんな権限を指定ファイルに付与したいかを決める)

基本の考え方

  • 誰がu(owner) / g(group) / o(others)
  • 何をr(読む) / w(書く) / x(実行/ディレクトリでは「辿る」)
  • 数字rwxを足す → 7=rwx, 6=rw-, 5=r-x, 4=r--
  • 記号:差分指定 → u+x, g-w, a-rw など

よく使うもの

  • chmod u+x script.sh
    自作スクリプトを実行可能にする

  • chmod 755 script.sh
    スクリプトを配布したいとき(自分:全て、他:読み実行〇書きは✖)

  • chmod 644 *.txt
    一般的なテキスト/設定ファイルの基本権限(自分:読み書き、他:読み)

  • chmod 600 ~/.ssh/id_rsa
    機密ファイル(秘密鍵など)は自分だけ読み書き

最後に

迷ったら、公開系は 755/644、共同編集系は 775/664、内部限定は 750/640 が目安だと思った。

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?