9

This question is about executing /usr/bin/Xorg directly on Ubuntu 14.04.

And I know there exists Xdummy, but I couldn't make the dummy driver work properly with the nvidia GPU so it's not an option.

I copied the system-wide xorg.conf and /usr/lib/xorg/modules, and modified them a little bit. (Specified ModulePath in my xorg.conf too)

Running the following command as root works fine:

Xorg -noreset +extension GLX +extension RANDR +extension RENDER -logfile ./16.log -config ./xorg.conf :16

But if I do that as a non-root user (the log file permission is OK), this error occurs:

(EE) 
Fatal server error:
(EE) xf86OpenConsole: Cannot open virtual console 9 (Permission denied)
(EE) 
(EE) 
Please consult the The X.Org Foundation support 
     at http://wiki.x.org
 for help. 
(EE) Please also check the log file at "./16.log" for additional information.
(EE) 
(EE) Server terminated with error (1). Closing log file.

Could you please help me to run Xorg without sudo??

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
noname
  • 274
  • 1
  • 3
  • 9
  • I don't think it's possible to run X as non-root; it needs to access lots of hardware and system stuff directly. – dirkt Oct 08 '16 at 18:15
  • 3
    set `setuid` bit on Xorg: `chmod +s $(which Xorg)` – Serge Oct 08 '16 at 20:06
  • @dirkt It's possible on recent systems but not with all drivers. See e.g. [Ubuntu](https://wiki.ubuntu.com/X/Rootless), [Debian](https://www.phoronix.com/scan.php?page=news_item&px=Debian-Non-Root-X), [Fedora](https://fedoraproject.org/wiki/Changes/XorgWithoutRootRights), [Gentoo](https://wiki.gentoo.org/wiki/Non_root_Xorg), [Arch](https://wiki.archlinux.org/index.php/xorg#Rootless_Xorg_.28v1.16.29), … – Gilles 'SO- stop being evil' Oct 08 '16 at 21:34
  • Thank you guys! It seems like your advice worked for me! – noname Oct 09 '16 at 09:40

2 Answers2

7

To determine who is allowed to run X configure it with

dpkg-reconfigure x11-common

There are three options: root only, console users only, or anybody. The entry is located in /etc/X11/Xwrapper.config.


Since Debian 9 and Ubuntu 16.04 this file does not exist. After installing xserver-xorg-legacy, the file reappears and its content has to be changed from:

allowed_users=console

to:

allowed_users=anybody
needs_root_rights=yes

You also need to specify the virtual terminal to use when starting X, otherwise, errors may occur. For example:

Xorg :8 vt8
Te Ri
  • 303
  • 2
  • 7
mviereck
  • 2,377
  • 1
  • 18
  • 18
5

X needs access to input devices (mouse and keyboard) and to the monitor and graphics card for output.

To achieve this for non-root X, you can change the group of Xorg from root to input, set the setgit bit, and add your user to group video:

chown root:input /usr/lib/xorg/Xorg
chmod g+s /usr/lib/xorg/Xorg
adduser YOURUSERNAME video

(Instead you could add your user to both video and input, but that is discouraged. A user in group input can spy on inputs of other users. E.g. a GUI in X could probably spy on root password typed into console/tty.)

mviereck
  • 2,377
  • 1
  • 18
  • 18