2013-02-08 74 views
1

现在我的web应用程序有我的本地机器如何更改我的金字塔/ python web应用程序目录的权限?

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

页目录下的HTML文件是由形式生成该文件的结构。我想使这个页面目录可写,以便用户可以通过应用程序向其添加html文件,但是使所有其他目录不可写且只能读取。我一直在阅读有关chmod和好像类似

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

会提出这样的网页目录可写。但是,如何确保只有该目录是可写的(所有其他目录都是不可写和只读的)?它只是

​​

显然我会执行这个命令第一。我执行它时应该在哪个目录中。如果我在本地机器上正确地完成了所有这些工作,我是否仍然能够开发(添加代码等),还是应该等到我完成了所有工作。当我将应用程序放在Web服务器上时,这些权限是否会被继续使用,还是必须以不同的方式再次执行?

回答

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

好的谢谢。在问题的其余部分的任何答案? – BigBoy1337 2013-02-08 23:07:25

2

在生产环境中,网络服务器通常以非特权用户身份运行,如www-data或其他。这些用户通常没有登录shell设置,并且在文件系统上没有任何文件,所以如果你的应用程序存在漏洞,攻击者可以在机器上运行任意代码,他们仍然不能修改任何文件。

所以,在生产环境中,确保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您的静态目录给该用户,以该用户身份打开一个终端shell并从那里运行服务器。

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

另外,在开发环境,你可以继续,因为你通常谁有权访问该服务器吗唯一的人跑的一切,你的普通登录用户。