Linux:怎么使用特定的用户启动程序

方法1,使用runuser命令

runuser - run a command with substitute user and group ID
如果不指定-u参数,就会使用当前的用户。runuser不会询问密码,这一点和su不同。当时要确保root用户运行。

#rpm -qf /usr/sbin/runuser
util-linux-2.32.1-28.el8.x86_64

如果是systemd带起来

systemd.exec
User=, Group=
Set the UNIX user or group that the processes are executed as, respectively. Takes a single user or group name, or a numeric ID as argument. For system services (services run by the system service manager, i.e. managed by PID 1) and for user services of the root user (services managed by root’s instance of systemd --user), the default is “root”, but User= may be used to specify a different user. For user services of any other user, switching user identity is not permitted, hence the only valid setting is the same user the user’s service manager is running as. If no group is set, the default group of the user is used. This setting does not affect commands whose command line is prefixed with “+”.

Note that restrictions on the user/group name syntax are enforced: the specified name must consist only of the characters a-z, A-Z, 0-9, “" and “-”, except for the first character which must be one of a-z, A-Z or "” (i.e. numbers and “-” are not permitted as first character). The user/group name must have at least one character, and at most 31. These restrictions are enforced in order to avoid ambiguities and to ensure user/group names and unit files remain portable among Linux systems.

When used in conjunction with DynamicUser= the user/group name specified is dynamically allocated at the time the service is started, and released at the time the service is stopped — unless it is already allocated statically (see below). If DynamicUser= is not used the specified user and group must have been created statically in the user database no later than the moment the service is started, for example using the sysusers.d(5) facility, which is applied at boot or package install time.

猜你喜欢

转载自blog.csdn.net/qq_36428903/article/details/124977518
今日推荐