nicholas@mordor:~$
nicholas@mordor:~$ xhost +
access control disabled, clients can connect from any host
nicholas@mordor:~$
nicholas@mordor:~$ sudo su - foo
[sudo] password for nicholas:
foo@mordor:~$
foo@mordor:~$ whoami
foo
foo@mordor:~$ pwd
/home/foo
foo@mordor:~$
foo@mordor:~$ firefox
Error: no DISPLAY environment variable specified
foo@mordor:~$
foo@mordor:~$ export DISPLAY=:0.0
foo@mordor:~$
foo@mordor:~$ firefox
^C
Exiting due to channel error.
Exiting due to channel error.
Terminated
foo@mordor:~$
在所有可能的方法?
系统信息:
nicholas@mordor:~$
nicholas@mordor:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal
nicholas@mordor:~$
答案1
尝试一下 sudo -u <username> <command>
,sudo 保留了像 DISPLAY 这样的环境变量。
$ xhost +SI:localuser:foo
localuser:foo being added to access control list
$ sudo -u foo firefox