How can I run /usr/bin/Xorg without sudo?

11,389

Solution 1

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

Solution 2

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.)

Share:
11,389

Related videos on Youtube

noname
Author by

noname

Updated on September 18, 2022

Comments

  • noname
    noname over 1 year

    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??

    • dirkt
      dirkt over 7 years
      I don't think it's possible to run X as non-root; it needs to access lots of hardware and system stuff directly.
    • Serge
      Serge over 7 years
      set setuid bit on Xorg: chmod +s $(which Xorg)
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' over 7 years
      @dirkt It's possible on recent systems but not with all drivers. See e.g. Ubuntu, Debian, Fedora, Gentoo, Arch, …
    • noname
      noname over 7 years
      Thank you guys! It seems like your advice worked for me!