概要: You can give customers the ability to create scheduled tasks that run commands on the server. In Plesk for Linux, the shell being used determines which areas of the file system scheduled tasks have access to. By default, access is limited to the customer’s webspace. However, Plesk administrator has the ability to change that.

In this topic, you will learn how to set the default shell for scheduled tasks, how to set a custom shell for an individual subscription, and also how to allow a customer to set a custom shell for their subscription. You will also learn how to prevent customers from using the “Run a Command” scheduled tasks.

Note: If you are not familiar with the concept of Linux shells, we recommend learning more before changing the settings described in this topic.

哪个shell 用于运行计划任务?

用于”运行命令” 计划任务的shell 与订阅的系统用户相关(也就是说某个订阅下的所有计划任务都共享相同的 shell)。默认会匹配在服务器设置中配置的且用于服务器上所有订阅的默认shell。但是仍有两个例外:

以上两种情况,在订阅下创建的”运行命令” 计划任务都将使用自定义的 shell 而不是默认的。

为何要使用其它的shell?

默认会将”/bin/bash (chrooted)” shell 配置为计划任务的默认shell。这样设置,计划任务所运行的命令则只能访问与订阅相关联的主机空间内的文件。这是很重要的安全举措,因为可以确保客户无法使用计划任务来干扰服务器的操作运行或访问属于Plesk管理员或其他客户的文件。

注解: This setting affects all subscriptions on the server, including those owned by the Plesk administrator. It does not affect the scheduled tasks created by the Plesk administrator in Tools & Settings > Scheduled Tasks (Cron jobs) (under “Tools & Resources”) that are configured to run under the root user.

您会为计划任务更改默认的shell的主要原因有可能是,让服务器上的每个用户都可以通过访问服务器上整个文件系统的计划任务来运行命令。

如果您不与任何人分享服务器,或者您信任其它的租户,则可以为计划任务 选一个非 chrooted shell 。如果您希望计划任务使用一个非 chrooted shell 但是又不确定选择哪一个,可选择 “/bin/bash”。

在虚拟主机服务器上,我们建议将计划任务的默认 shell 保持设置为 “/bin/bash (chrooted)”。如果您的某一个客户需要为其计划任务设置一个非 chrooted shell,则可以订阅为基础 允许 其某个订阅使用该设置。

警告: 允许客户访问任何其它的 shell 而非 “/bin/bash (chrooted)”,客户则可以执行二进制文件和访问本不属于他们的文件和数据。这存在一定安全风险,服务器可能会受影响。

为计划任务设置默认的 shell

To set the shell that will be used to run all “Run a Command” scheduled tasks by default, go to Tools & Settings > Scheduled Tasks (Cron jobs) (under “Tools & Resources”) > Settings and select the desired shell from the menu.

image select shell

此外,您可以通过 ssh 登录服务器并运行以下命令:

plesk bin server_pref -u -crontab-secure-shell "<shell>"

其中 <shell> 是所需的 shell。例如:

plesk bin server_pref -u -crontab-secure-shell "/bin/bash"

阻止使用”运行命令” 计划任务

如果您认为您的某个客户已创建了一个会在服务器上执行恶意行为的计划任务(例如,发送垃圾邮件),您可以在调查时禁用所有的 “运行命令” 计划任务。

通过ssh登录到Plesk服务器并运行以下命令

plesk bin server_pref -u -crontab-secure-shell "/bin/false"

将计划任务的默认 shell 设置为 “/bin/false”。这样会令客户创建的所有”运行命令” 计划任务执行失败。

注解: Customers that have the permission to select a different shell can override this for their subscriptions by selecting a different shell.

为单个订阅设置自定义 shell

若要为单个订阅设置自定义 shell,请如下操作:

  1. Go to Subscriptions, click the desired subscription, go to the “Hosting & DNS” tab, and then click Hosting.
  2. Select the desired shell from the “SSH Access” menu and click Save.

该订阅所有的 “运行命令” 计划任务都将使用选定的 shell。

允许客户为其订阅设置自定义 shell

若要允许客户为其订阅设置自定义 shell,请如下操作:

  1. 进入 订阅 ,点击所需的订阅,然后点击 自定义
  2. 在”权限” 标签上,勾选 “主机设置管理” 和 “设置存在安全隐患的 web 脚本选项(会覆盖提供商策略)” 复选框,然后点击 更新并锁定

This will give the customer the ability to select a different shell in Websites & Domains > “Hosting & DNS” tab > Hosting. If they do, all “Run a Command” scheduled tasks for their subscription will use the selected shell.

查找订阅所使用的shell

若要查找某个订阅的”运行命令”计划任务所使用的shell,请如下操作:

  1. Look up the username of the subscription’s system user. Go to Subscriptions, click the desired subscription, go to the “Hosting & DNS” tab, click Hosting, and then look for the “Username” field.
  2. 通过ssh登录到Plesk服务器并运行以下命令:
crontab -u <system user name> -l | grep SHELL