【问题标题】:Making a Python script executable chmod755?使 Python 脚本可执行 chmod755?
【发布时间】:2010-10-28 19:11:01
【问题描述】:

我的托管服务提供商说我的 python 脚本必须是可执行的 (chmod755)。这是什么意思?我该怎么做?

干杯!

【问题讨论】:

  • 它的意思是“每个人都可读和可执行,只有所有者可以写”。如果您有 shell 访问权限,@Jian Lin 的回答很好;否则,您的提供商可能会在上传时保留完整的权限位(在这种情况下,您需要在上传之前设置它们)——如果两者都不适用,您的提供商必须记录如何为其特定设置设置权限位。

标签: python hosting


【解决方案1】:

如果您可以通过 ssh 访问您的网络空间,请连接并发出

chmod 755 nameofyourscript.py

如果您没有 ssh 访问权限而是通过 FTP 连接,请检查您的 FTP 应用程序以查看它是否支持设置权限。

关于755的含义:

  • 第一位是用户设置(您自己)
  • 第二个数字是组设置
  • 第三位数字是系统的其余部分

数字是通过添加权限值来构造的。 1 = 可执行,2 = 可写,4 = 可读。 IE。 755表示你自己可以读、写和执行文件,其他人也可以读和执行。

【讨论】:

    【解决方案2】:

    类 Unix 系统具有“文件模式”,表明谁可以读/写/执行文件。模式 755 意味着所有者可以读/写/执行,其他人可以读/执行但不能写。要使您的 Python 脚本具有此模式,请键入

    chmod 0755 script.py
    

    你还需要一个像这样的shebang

    #!/usr/bin/python
    

    在文件的第一行告诉操作系统它是什么类型的脚本。

    【讨论】:

      【解决方案3】:

      这意味着某人(用户、组或每个人)有权执行(或读取或写入)脚本(或一般的文件)。

      权限以不同的方式表示:

      $ chmod +x file.py # makes it executable by anyone
      $ chmod +w file.py # makes it writeabel by anyone
      $ chmod +r file.py # makes it readably by anyone
      
      $ chmod u+x file.py # makes it executable for the owner (user) of the file
      $ chmod g+x file.py # makes it executable for the group (of the file)
      $ chmod o+x file.py # makes it executable for the others (everybody)
      

      您可以用同样的方式取消权限,只需将+ 替换为-

      $ chmod o-x file.py # makes a file non-executable for the others (everybody)
      $ ...
      

      八进制数以不同的方式表示相同的数字。 4是读,2写,1执行。

      简单的数学:

      read + execute = 5
      read + write + execute = 7
      execute + write = 3
      ...
      

      将所有内容打包在一个简短而甜蜜的命令中:

      # 1st digit: user permissions
      # 2nd digit: group permissions
      # 3rd digit: 'other' permissions
      
      # add the owner all perms., 
      # the group and other only write and execution
      
      $ chmod 755 file.py
      

      【讨论】:

        【解决方案4】:

        在 shell(如 bash)上,只需键入

        chmod 755 file.py
        

        使其可执行。你可以使用

        ls -l file.py
        

        验证是否设置了执行权限(“rwxr-xr-x”中的“x”)

        【讨论】:

          【解决方案5】:

          除了这里的其他很好的答案,您应该知道大多数 FTP 客户端都有一个chmod 命令来允许您在服务器上设置文件的权限。如果权限正确获得,您可能不需要这个,但很有可能他们不需要。

          【讨论】:

            猜你喜欢
            • 2014-07-05
            • 2014-08-09
            • 2015-02-14
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-08-17
            • 2016-08-02
            相关资源
            最近更新 更多