Linux переключить пользователя и немедленно выполнить команду

Обычно файл спецификации есть только у исходных RPM. Вы можете извлечь его с помощью

rpm2cpio myrpm.src.rpm | cpio -civ '*.spec'

или установить src rpm как пользователь с помощью rpm -i myrpm.src.rpm , когда каталог rpmbuild / SPECS / получит файл спецификации.

8
26.09.2017, 08:23
3 ответа

Попробуйте.

sudo -H -u TARGET_USER bash -c 'bash /usr/local/hadoop/sbin/start-dfs.sh' 

см. man sudo:

-H

The -H (HOME) option requests that the security policy set the HOME environment variable to the home directory of the target user (root by default) as specified by the password database. Depending on the policy, this may be the default behavior.

-u user

The -u (user) option causes sudo to run the specified command as a user other than root. To specify a uid instead of a user name, use #uid. When running commands as a uid, many shells require that the '#' be escaped with a backslash ('\'). Security policies may restrict uids to those listed in the password database. The sudoers policy allows uids that are not in the password database as long as the targetpw option is not set. Other security policies may not support this.

26
27.01.2020, 20:08

Вы можете попробовать это:

pkexec - Execute a command as another user

pkexec [--user username] PROGRAM [ARGUMENTS...]

1
27.01.2020, 20:08

Вот сокращенная версия ответа αғsнιη:

sudo -Hu user command
# example: sudo -Hu root fish
4
27.01.2020, 20:08

Теги

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