1

現在、私のWebアプリはローカルマシン上にこのファイル構造を持っています

 env
    tutorial
        tutorial
            templates
                home.pt
            static
                pages
                    1.html
                    2.html
                    3.html
                     ....
            views.py
            __init__.py

pagesディレクトリの下のhtmlファイルはフォームによって生成されます。このページのディレクトリを書き込み可能にして、ユーザーがアプリを介してhtmlファイルを追加できるようにしますが、他のすべてのディレクトリは書き込み不可で読み取り可能にします。私はchmodについて読んでいますが、

chmod a+x env/tutorial/tutorial/static/pages

そのページのディレクトリを書き込み可能にします。しかし、ディレクトリが書き込み可能である(他のすべては書き込み不可で読み取り専用である)ことだけを確認するにはどうすればよいですか?それはただでしょうか

chmod a-x env

明らかに、私は最初にこのコマンドを実行します。実行するときに、どのディレクトリに配置する必要がありますか。そして、ローカルマシンでこれらすべてを正しく実行した場合でも、開発(コードの追加など)は可能ですか、それともすべて完了するまで待つ必要があります。アプリケーションをWebサーバーに配置すると、これらのアクセス許可は引き継がれますか、それとも別の方法で再度実行する必要がありますか?

4

2 に答える 2

2

www-data実稼働環境では、Web サーバーは通常、または何かなどの非特権ユーザーとして実行されます。このようなユーザーは通常、ログイン シェル セットを持たず、ファイル システム上にファイルを所有していません。そのため、アプリケーションの欠陥により、攻撃者がマシン上で任意のコードを実行できる場合でも、ファイルを変更することはできません。

そのため、実稼働環境で Web サーバー ユーザーがファイルを変更できないようにする最も簡単な方法は、ファイルの所有権を Web サーバーの有効なユーザー以外のユーザーに変更することです。通常のログイン ユーザーまたはroot適切な候補:

chown -R bigboy:bigboy /opt/where/my/code/is

また

sudo chown -R root:root /opt/where/my/code/is

通常のumask設定では、Web サーバーはファイルを読み取ることができますが、何も書き込むことはできません。典型的な Web アプリケーションに最適です。

したがって、Web サーバーにディレクトリへの書き込みアクセスを許可するには、ディレクトリの所有権を Web サーバーの有効なユーザーに変更します。

sudo chown -R www-data /opt/where/my/static/directory/is

開発環境では、通常pserve、通常のログイン ユーザーとしてコマンドを実行するため、ファイルを編集できないため、ユーザーから読み取り権限を取り消すことは実際的ではありません。最も簡単な方法は、別のユーザーをシステムに追加し、chown静的ディレクトリをそのユーザーに追加し、そのユーザーとしてターミナル シェルを開き、そこからサーバーを実行することです。

sudo chown -R testuser:testuser env/tutorial/tutorial/static/pages
sudo su testuser
env/bin/pserve ...

または、開発環境では、サーバーにアクセスできるのは通常あなただけなので、通常のログイン ユーザーとしてすべてを実行し続けることができます。

于 2013-02-09T10:52:24.987 に答える
1

いいえ、

chmod a+x env/tutorial/tutorial/static/pages

そのディレクトリに実行ビットを設定します。必要なのは、レールを実行するユーザー (または場合によってはグループ) ごとに、そのディレクトリに書き込みビットを設定することです。現在のユーザーに対して、次のようにします。

chmod +w env/tutorial/tutorial/static/pages

chmod マンページから -- 下部のシンボリック モード テーブルを見てください (Mac OSX):

MODES
 Modes may be absolute or symbolic.  An absolute mode is an octal number constructed from the sum of one or more
 of the following values:

       4000    (the set-user-ID-on-execution bit) Executable files with this bit set will run with effective uid
               set to the uid of the file owner.  Directories with the set-user-id bit set will force all files
               and sub-directories created in them to be owned by the directory owner and not by the uid of the
               creating process, if the underlying file system supports this feature: see chmod(2) and the
               suiddir option to mount(8).
       2000    (the set-group-ID-on-execution bit) Executable files with this bit set will run with effective gid
               set to the gid of the file owner.
       1000    (the sticky bit) See chmod(2) and sticky(8).
       0400    Allow read by owner.
       0200    Allow write by owner.
       0100    For files, allow execution by owner.  For directories, allow the owner to search in the directory.
       0040    Allow read by group members.
       0020    Allow write by group members.
       0010    For files, allow execution by group members.  For directories, allow group members to search in
               the directory.
       0004    Allow read by others.
       0002    Allow write by others.
       0001    For files, allow execution by others.  For directories allow others to search in the directory.

 For example, the absolute mode that permits read, write and execute by the owner, read and execute by group mem-
 bers, read and execute by others, and no set-uid or set-gid behaviour is 755 (400+200+100+040+010+004+001).

 The symbolic mode is described by the following grammar:

       mode         ::= clause [, clause ...]
       clause       ::= [who ...] [action ...] action
       action       ::= op [perm ...]
       who          ::= a | u | g | o
       op           ::= + | - | =
       perm         ::= r | s | t | w | x | X | u | g | o
于 2013-02-08T21:05:53.683 に答える