Execute commands as other users
pkexec Allows an authorized user to execute PROGRAM as another user. if not specified PROGRAM, the default shell will run. If no username is specified, the program will run as the administrative superuser root identity execution.
pkexec [--version] [--disable-internal-agent] [--help]
pkexec [--keep-cwd] [--user username] PROGRAM [ARGUMENTS...]
PROGRAM Program to run
ARGUMENTS... Arguments passed to the program
--version output version number and exit
--disable-internal-agent avoid registering your own text authentication agent
--help print help text and exit
--keep-cwd running location, default is /home/<username>/
--user <username> User name to run
On successful completion, the return value is the return value of PROGRAM.
Run the command with administrator privileges:
pkexec command
Replace command with the command you want to run with administrator privileges. For example, pkexec ls will run the ls command with administrator privileges.
Run the command with administrator privileges in the graphical interface:
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY command
This command is used to run commands that require administrator privileges in the graphical interface. Replace command with the command you want to run with administrator privileges.
Run the command with a specific authentication agent:
pkexec --user username command
Replace username with the username of the user you want to run the command as, and command with the command you want to run.
View the help information of pkexec:
pkexec --help
This command will display instructions and a list of options for pkexec.
Note that when running a command using pkexec, you will be prompted for the administrator password to authenticate. Make sure to use pkexec only when necessary to run commands that require administrator privileges, and handle administrator privileges with caution.
优先推荐相关内容,同时保留你的阅读轨迹和收藏入口。