Linux-admin-file-folder-management

提供:Dev Guides
移動先:案内検索

Linux Admin-ファイル/フォルダー管理

CentOS Linuxのディレクトリとファイルの両方に適用される許可を導入するために、次のコマンド出力を見てみましょう。

[centos@centosLocal etc]$ ls -ld/etc/yum*
drwxr-xr-x. 6 root root 100 Dec  5 06:59/etc/yum
-rw-r--r--. 1 root root 970 Nov 15 08:30/etc/yum.conf
drwxr-xr-x. 2 root root 187 Nov 15 08:30/etc/yum.repos.d

-表示される3つの主要なオブジェクトタイプは

  • _ "-" _ -プレーンファイルのダッシュ
  • _ "d" _ -ディレクトリの場合
  • _ "l" _ -シンボリックリンクの場合

私たちは、各ディレクトリとファイルの出力の3つのブロックに焦点を当てます-

  • drwxr-xr-x:ルート:ルート
  • -rw-r—​r--:ルート:ルート
  • drwxr-xr-x:ルート:ルート

今、これらの行をよりよく理解するために、これを分解しましょう-

d Means the object type is a directory
rwx Indicates directory permissions applied to the owner
r-x Indicates directory permissions applied to the group
r-x Indicates directory permissions applied to the world
root The first instance, indicates the owner of the directory
root The second instance, indicates the group to which group permissions are applied

owner _、 group_、および_world_の違いを理解することが重要です。 これを理解しないと、インターネットへのサービスをホストするサーバーに大きな影響を及ぼす可能性があります。

実際の例を示す前に、_directories_と_files_に適用されるアクセス許可を理解しましょう。

次の表をご覧になり、指示に従ってください。

Octal Symbolic Perm. Directory
1 x Execute Enter the directory and access files
2 w Write Delete or modify the files in a directory
4 r Read List the files within the directory

注意-ディレクトリの読み取りのためにファイルにアクセスできる必要がある場合、_read_および_execute_パーミッションを適用するのが一般的です。 そうしないと、ユーザーはファイルの操作が困難になります。 _write_を無効のままにすると、ファイルの名前変更、削除、コピー、またはアクセス許可の変更ができなくなります。

ディレクトリとファイルへのアクセス許可の適用

アクセス許可を適用する場合、理解する必要がある2つの概念があります-

  • シンボリック許可
  • オクタル許可

本質的に、それぞれは同じですが、ファイル許可を参照し、割り当てる方法が異なります。 クイックガイドについては、次の表を調べて参照してください-

Read Write Execute
Octal 4 2 1
Symbolic r w x
*octal* メソッドを使用してアクセス許可を割り当てるときは、760などの3バイトの数値を使用します。 数字760は次のように変換されます。所有者:rwx。グループ:rw;その他(または世界)の許可なし。

別のシナリオ:733は次のように変換されます:Owner:rwx;グループ:wx;その他:wx。

Octalメソッドを使用したアクセス許可には1つの欠点があります。 既存の許可セットは変更できません。 オブジェクトの権限セット全体を再割り当てすることのみが可能です。

今、あなたは不思議に思うかもしれません、常に許可を再割り当てすることの何が悪いのでしょうか? 実稼働Webサーバー上の_/var/www/_などの大きなディレクトリ構造を想像してください。 Otherのすべてのディレクトリで_w_または_write bit_を再帰的に削除します。 したがって、セキュリティ対策のために必要な場合にのみ、積極的に追加することを強制します。 権限セット全体を再割り当てすると、すべてのサブディレクトリに割り当てられた他のすべてのカスタム権限が削除されます。

したがって、システムの管理者とユーザーの両方に問題が発生します。 ある時点で、個人(または個人)は、すべてのディレクトリとオブジェクトのパーミッションセット全体を再割り当てすることにより、消去されたすべてのカスタムパーミッションを再割り当てする必要があります。

この場合、我々はシンボリックメソッドを使用してアクセス許可を変更したいでしょう-

chmod -R o-w/var/www/

上記のコマンドは「許可を上書き」しませんが、現在の許可セットを変更します。 そのため、ベストプラクティスの使用に慣れる

  • 許可を割り当てるためだけの8進数
  • 許可セットを変更するシンボリック

CentOS管理者は、_Octal_パーミッションと_Symbolic_パーミッションの両方に習熟していることが重要です。パーミッションは、データとオペレーティングシステム全体の整合性にとって重要です。 アクセス許可が正しくない場合、最終結果は機密データとなり、オペレーティングシステム全体が危険にさらされます。

それがカバーされているので、パーミッションとオブジェクトの所有者/メンバーを変更するためのいくつかのコマンドを見てみましょう-

  • chmod
  • チャウン
  • chgrp
  • 仮面

chmod:ファイルモード許可ビットの変更

Command Action
-c Like verbose, but will only report the changes made
-v Verbose, outputsthe diagnostics for every request made
-R Recursively applies the operation on files and directories

chmodにより、_octal_または_symbolic_許可セットを使用してディレクトリとファイルの許可を変更できます。 これを使用して、割り当てを変更し、ディレクトリをアップロードします。

chown:ファイルの所有者とグループの変更

Command Action
-c Like verbose, but will only report the changes made
-v Verbose, outputsthe diagnostics for every request made
-R Recursively applies the operation on files and directories

_chown_は、所有するユーザーとオブジェクトのグループの両方を変更できます。 ただし、両方を同時に変更する必要がない限り、_chgrp_の使用は通常グループに使用されます。

chgrp:ファイルまたはディレクトリのグループ所有権の変更

Command Action
-c Like verbose, but will only report the changes
-v Verbose, outputs the diagnostics for every request made
-R Recursively, applies the operations on file and directories

chgrpは、グループ所有者を指定された所有者に変更します。

実世界の練習

所有グループが_students_グループになるように、_/var/www/students/_内のすべてのサブディレクトリの割り当てを変更しましょう。 次に、_students_のルートを教授グループに割り当てます。 後で、博士を作ります _students_ディレクトリの所有者であるTerry Thomasは、学校のすべてのコンピューターサイエンスアカデミアを担当する任務を負っています。

ご覧のとおり、作成されたディレクトリはかなり未加工のままです。

[root@centosLocal ~]# ls -ld/var/www/students/
drwxr-xr-x. 4 root root 40 Jan  9 22:03/var/www/students/

[root@centosLocal ~]# ls -l/var/www/students/
total 0
drwxr-xr-x. 2 root root 6 Jan  9 22:03 assignments
drwxr-xr-x. 2 root root 6 Jan  9 22:03 uploads

[root@centosLocal ~]#

管理者として、私たちは_root_資格情報をだれにも公開したくありません。 しかし同時に、ユーザーが仕事を行えるようにする必要があります。 だから博士を許可しましょう Terry Thomasは、ファイル構造をさらに制御し、学生ができることを制限します。

[root@centosLocal ~]# chown -R drterryt:professors/var/www/students/
[root@centosLocal ~]# ls -ld/var/www/students/
drwxr-xr-x. 4 drterryt professors 40 Jan  9 22:03/var/www/students/

[root@centosLocal ~]# ls -ls/var/www/students/
total 0
0 drwxr-xr-x. 2 drterryt professors 6 Jan  9 22:03 assignments
0 drwxr-xr-x. 2 drterryt professors 6 Jan  9 22:03 uploads

[root@centosLocal ~]#

現在、各ディレクトリとサブディレクトリの所有者は_drterryt_で、所有グループは_professors_です。 _assignments_ディレクトリは学生が割り当てられた課題を提出するためのものであるため、_students_グループから_files_をリストおよび変更する機能を削除しましょう。

[root@centosLocal ~]# chgrp students/var/www/students/assignments/&& chmod
736/var/www/students/assignments/

[root@centosLocal assignments]# ls -ld/var/www/students/assignments/
drwx-wxrw-. 2 drterryt students 44 Jan  9 23:14/var/www/students/assignments/

[root@centosLocal assignments]#

学生は課題を_assignments_ディレクトリにコピーできます。 ただし、ディレクトリの内容を一覧表示したり、現在のファイルをコピーしたり、_assignments_ディレクトリ内のファイルを変更したりすることはできません。 したがって、学生は完了した課題を提出することができます。 CentOSファイルシステムは、割り当てが有効になったときの日付スタンプを提供します。

_assignments_ディレクトリの所有者として-

[drterryt@centosLocal assignments]$ whoami
drterryt

[drterryt@centosLocal assignments]$ ls -ld/var/www/students/assignment
drwx-wxrw-. 2 drterryt students 44 Jan  9 23:14/var/www/students/assignments/

[drterryt@centosLocal assignments]$ ls -l/var/www/students/assignments/
total 4
-rw-r--r--. 1 adama  students  0 Jan  9 23:14 myassign.txt
-rw-r--r--. 1 tammyr students 16 Jan  9 23:18 terryt.txt

[drterryt@centosLocal assignments]$

ディレクトリの所有者は、ファイルをリストしたり、ファイルを変更および削除したりできます。

umaskコマンド:ファイルおよびディレクトリのアクセス許可のデフォルトモードを作成時に提供する

_umask_は、ファイルとディレクトリの作成時にデフォルトのモードを提供する重要なコマンドです。

_umask_パーミッションは、単項否定論理を使用します。

Permission Operation
0 Read, write, execute
1 Read and write
2 Read and execute
3 Read only
4 Read and execute
5 Write only
6 Execute only
7 No permissions
[adama@centosLocal umask_tests]$ ls -l ./
-rw-r--r--. 1 adama students 0 Jan 10 00:27 myDir
-rw-r--r--. 1 adama students 0 Jan 10 00:27 myFile.txt

[adama@centosLocal umask_tests]$ whoami
adama

[adama@centosLocal umask_tests]$ umask
0022

[adama@centosLocal umask_tests]$

では、現在のユーザーの_umask_を変更して、新しいファイルとディレクトリを作成しましょう。

[adama@centosLocal umask_tests]$ umask 077

[adama@centosLocal umask_tests]$ touch mynewfile.txt

[adama@centosLocal umask_tests]$ mkdir myNewDir

[adama@centosLocal umask_tests]$ ls -l
total 0
-rw-r--r--. 1 adama students 0 Jan 10 00:27 myDir
-rw-r--r--. 1 adama students 0 Jan 10 00:27 myFile.txt
drwx------. 2 adama students 6 Jan 10 00:35 myNewDir
-rw-------. 1 adama students 0 Jan 10 00:35 mynewfile.txt

ご覧のとおり、新しく作成されたファイルは以前よりも少し制限が厳しくなります。

ユーザーの_umask_はどちらかで変更する必要があります-

  • /etc/profile * 〜/bashrc
[root@centosLocal centos]# su adama
[adama@centosLocal centos]$ umask
0022
[adama@centosLocal centos]$

通常、CentOSのデフォルトの_umask_は問題ありません。 デフォルトの_0022_で問題が発生するのは、通常、異なるグループに属する異なる部門がプロジェクトで協力する必要がある場合です。

CentOSオペレーティングシステムの操作と設計のバランスを取るために、ここでシステム管理者の役割が入ります。