if ($answer_counter == 1): ?>
endif; ?>
Вы можете сделать это с помощью su
или sudo
, не нужно обоим.
sudo -H -u otheruser bash -c 'echo "I am $USER, with uid $UID"'
Соответствующие части 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.
su
может переключать пользователя без предоставления пароля, если вы являетесь пользователем root. См. Ответ Калеба
Вы можете изменить файл /etc/pam.d/su
, чтобы разрешить su
без пароля. См. ответ . Р>
Если вы изменили свой файл авторизации на следующий, любой пользователь, входящий в группу somegroup
, мог бы su
до otheruser
без пароля.
auth sufficient pam_rootok.so
auth [success=ignore default=1] pam_succeed_if.so user = otheruser
auth sufficient pam_succeed_if.so use_uid user ingroup somegroup
Затем проверьте с терминала
[email protected]$ su otheruser -c 'echo "hello from $USER"'
hello from otheruser