Выполните сценарий от rc.local как пользователь вместо корня

Взгляните на Тюремщика Linux, серия готовых виртуальных машин на основе Ubuntu. Они имеют устройство Drupal 6 в наличии. Они намного легче, чем стандартная установка Linux, потому что они не учитывают многие компоненты, требуемые только при выполнении на физическом оборудовании.

26
задан 30 August 2012 в 19:04
4 ответа

Running sudo su user01 in a script does not mean the following commands are sent to the resultant shell. In fact, it likely means a new shell is spawned as user01, which never exits!

Two things:

  • You can execute a command as another user either by passing the -c 'command...' argument to su, like su user01 -c '/etc/init.d/script start'.
  • Starting a service that uses /etc/init.d from rc.local isn't the correct thing to do. You want to use enable the service at startup using your distribution tools, like chkconfig or update-rc.d. You also don't want jobs in /etc/init.d that shouldn't be started as root. The jobs themselves can feel free to fork to another user account, but should be invoked by root.
30
ответ дан 28 November 2019 в 20:09

You could put something in /etc/crontab and run it @reboot

@reboot username /etc/init.d/script start
8
ответ дан 28 November 2019 в 20:09

Конечно, вы не можете запустить этот скрипт с sudo из-за requiretty (заставляет пользователей входить в систему) в sudoers. Вы можете захотеть отключить, что несколько рискованно.

Также есть несколько старый инструмент под названием runsuid: http://freecode.com/projects/runsuid

HTH

0
ответ дан 28 November 2019 в 20:09

Можно просто запустить команду через sudo так:

sudo -H -u user01 /etc/init.d/script start

-H устанавливает переменную окружения HOME равной пользователю

-u указывает имя пользователя для запуска как

.
4
ответ дан 28 November 2019 в 20:09

Теги

Похожие вопросы