33

So when i try to use the Xorg command as a normal user, this is the error that it gives me :

/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server

but i don't understand, what are the "console users"? and when i switch to root it gives me another error :

_XSERVTransSocketUNIXCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
(EE) 
Fatal server error:
(EE) Cannot establish any listening sockets - Make sure an X server isn't already running(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 "/var/log/Xorg.0.log" for additional information.
(EE) 
(EE) Server terminated with error (1). Closing log file.

So what is going on and what are the reason for each of these errors?

UPDATE: and the output of the command netstat -ln | grep -E '[.]X|:6[0-9][0-9][0-9] is :

unix  2      [ ACC ]     STREAM     LISTENING     18044    @/tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     47610    @/tmp/.X11-unix/X1
unix  2      [ ACC ]     STREAM     LISTENING     18045    /tmp/.X11-unix/X0
unix  2      [ ACC ]     STREAM     LISTENING     47611    /tmp/.X11-unix/X1
sourcejedi
  • 48,311
  • 17
  • 143
  • 296
John P
  • 1,053
  • 2
  • 10
  • 20
  • @sourcejedi can you give me a link or resource that explains this console user? i googled console users in linux but there was nothing! – John P Oct 30 '18 at 20:35
  • please edit your question to note the version of Debian. The question I linked claimed that Xwrapper is not used anymore in Debian 9. (I *think* the "console users" error comes from Xwrapper, although it's possible your message comes from new-style Xorg that you run directly and which gains access using `systemd-logind`. – sourcejedi Oct 30 '18 at 20:36
  • @sourcejedi I'm actually using Kali linux which is debian based, the kali version is 2018.4, also when i run it as root it won't give me that console user error anymore, but some new types of error : Fatal server error: (EE) Cannot establish any listening sockets - Make sure an X server isn't already running(EE) – John P Oct 30 '18 at 20:45
  • @sourcejedi it still gave me the same error – John P Oct 31 '18 at 07:29
  • Please read [this](https://unix.stackexchange.com/questions/399626/why-is-kali-linux-so-hard-to-set-up-why-wont-people-help-me), and do yourself a favour and switch from Kali to some other distro (e.g. another Debian based one). Kali is meant to be put on a USB stick, and then you walk into some company and do penetration testing. It's not meant for daily usage, and you'll encounter funny stuff when you try to. You'll still be able to use all the hacking tools Kali has on another distro. – dirkt Oct 31 '18 at 10:07
  • 1
    @sourcejedi yes it changed from Xorg.0.log to Xorg.1.log, and i updated the question for the output of the command you mentioned – John P Oct 31 '18 at 13:37
  • @dirkt I actually don't use it that much, but I'm interested in problems like this because it makes me learn more stuff, fixing it just by switching to another distro is not my main goal here – John P Oct 31 '18 at 13:39
  • If you want to fix stuff: The X server wants to create a unix domain socket in /tmp/.X11-unix. Root doesn't have the privileges to do so, for whatever reasons. As for `Xorg.wrap`, have a look at it, maybe it's just a script. In any case, X will want to access hardware or at least stuff provided by kernel modules, so it needs the permissions on top of being able to create the unix domain socket. Which is why the X server is often run as root, and started from the display manager, and not started by a normal user. – dirkt Oct 31 '18 at 13:50
  • In any case, it's much easier to learn how this stuff works by looking at it in a working distro, and not in a broken distro like Kali, which isn't set up properly for these things. – dirkt Oct 31 '18 at 13:52
  • Thanks, you need to run `Xorg :2` :-). I'm used to Fedora: login screen gets display 1024, first graphical login gets display 0, and so display 1 is free. For some reason, your OS is using display 0 and 1. This might happen if you have two different users logged in graphically at the same time, or maybe your login screen uses display 0, I dunno. – sourcejedi Oct 31 '18 at 14:09
  • @sourcejedi thanks, but can you explain a bit why that error happened and what is Xorg :2 is actually doing? why 2? or maybe suggesting a good resource where i can read about it? the manual of Xorg is really confusing and doesn't explain much, and i couldn't find any useful tutorial as well. – John P Oct 31 '18 at 14:15
  • 1
    @dirkt how can root not have the privilege for that? i thought root has all the privileges – John P Oct 31 '18 at 14:20

5 Answers5

45

If you are sure about the security implications (anyone can start the X-Server with root rights, which, since it has privileged hardware access and accesses a lot of files can open up a big security hole) and care only for functionality, not for security, for this part of your problem:

So when i try to use the Xorg command as a normal user, this is the error that it gives me :

/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server

the following can help:

You can add to

/etc/X11/Xwrapper.config

the line

allowed_users = anybody

Explanation from man Xorg.wrap:

CONFIG FILE
[...]
allowed_users = rootonly|console|anybody

Specify which users may start the X server through the wrapper. Use rootonly to only allow root, use console to only allow users logged into a physical console, and use anybody to allow anybody. The default is console.

Golar Ramblar
  • 1,771
  • 1
  • 18
  • 28
  • Don't do this... When X is already running and if another user (whoever) tries to call it again everything will crash. – 71GA Apr 16 '21 at 10:34
  • @71GA: If the machine is used just by a single user, without remote login, like a personal laptop, then this scenario should not apply. If other users who you not really trust can access the machine, then they should not be allowed to run X with root rights anyway. – Golar Ramblar Apr 17 '21 at 22:26
  • Two processes can call X server on the same machine... It can apply. I tried this and it crashed my computer. – 71GA Apr 19 '21 at 07:24
  • @71GA: When two processes want to start an X server on the same virtual console andwith the same display (`$DISPLAY`-variable), then something is wrong anyways. And yes, as a user of a machine you can and are allowed to crash the stuff you have the right to run and maintain. – Golar Ramblar Mar 31 '23 at 16:33
  • Worked fine for me. – Martin Dorey Apr 11 '23 at 23:34
13
/usr/lib/xorg/Xorg.wrap: Only console users are allowed to run the X server

but i don't understand, what are the "console users"?

It means you need to be running from the Linux text console, it actually does not matter what user you are. (Except that root is always allowed). Confusing :).

There are two different examples of switching to the Linux text console (and back) here, depending on exactly how your system is configured:

Switch to a text console in Fedora

The details can vary, as to which numbered consoles (Ctrl+Alt+F1, Ctrl+Alt+F2, etc) allow a text login, and which ones are used for graphical sessions (or not used at all).


I keep getting the message: "Cannot establish any listening sockets..."

You get an error message like:

_XSERVTransSocketINETCreateListener: ...SocketCreateListener() failed
_XSERVTransMakeAllCOTSServerListeners: server already running
Fatal server error:
Cannot establish any listening sockets - Make sure an X server isn't already running

This problem is very similar to the previous one. You will get this message possibly because the lock file was removed somehow or some other program which doesn't create a lock file is already listening on this port. You can check this by doing a netstat -ln. Xservers usually listen at tcp port 6000+, therefore if you have started your Xserver with the command line option :1 it will be listening on port 6001. Please check the article above for further information.

As this says, there is more information about what :0, :1, :2 mean, immediately above the quoted section:

https://www.x.org/wiki/FAQErrorMessages/#index5h2

(Note that you are using a more modern X server config, which does not listen on any TCP ports. This is why your error happens in _XSERVTransSocketUNIXCreateListener, instead of _XSERVTransSocketInetCreateListener. But the principle is exactly the same).

When i tried Xorg :2 in my virtual machine with Kali, the screen went black, why did this happen?

A-ha, yes :-D. Xorg is a graphics server. If you want to show some graphics on it, you need to run some client programs.

Xorg also starts up with an empty cursor nowadays. It's deliberately featureless, to avoid flashes / inconsistencies when starting your graphical stuff. This has changed - when I first used Xorg, the default background and cursor were quite obtrusive. If you want to see what that looked like, you can pass the -retro option :-).

Traditionally - and I think this is the behaviour with Xwrapper - Xorg would grab an unused console and switch to it. In this case you can switch back to your previous console (see above). Of course you can switch back again to the Xorg server, once you find which number console it grabbed :-).

If you are running a virtual machine on Linux, your VM will provide some method to inject the key combination Ctrl+Alt+F1 or whatever, because pressing that key combination probably switches consoles on your real machine.

I would tell you to compare startx -- :2, which (hopefully) launches some clients as well as an X server :-). However, the most popular modern GUIs now explicitly do not support multiple sessions. So you must make sure to logout your existing GUI session, before you run startx. Otherwise, it might look like it works, but then go wrong in weird ways that you don't understand.

sourcejedi
  • 48,311
  • 17
  • 143
  • 296
  • Thanks for the answer, one thing i forgot to mention is when i tried Xorg :2 in my virtual machine with Kali, the screen went black, why did this happen? – John P Oct 31 '18 at 15:57
  • @JohnP edited. The answer is "because you started Xorg". However, this is unsettling and it was clear you weren't familiar with Xorg, so I think the answer probably does need to say something about why this is expected. – sourcejedi Oct 31 '18 at 16:35
1

I was using the startx command to start DWM and I inserted it in my bashrc so that I won't have to type the startx command manually everytime I login that's when I started getting the 'only console users are allowed to use teh x server' error SO i removed the startx command from the bashrc that means i have to start the server manually but now I don't get the error anymore

aditya
  • 19
  • 1
  • 1
    You should not add it in the `.bashrc`. Commands in there are executed every time you open another terminal. Instead you should add it to the `.bash_profile`. Comands in here will be executed only at login. – 71GA Apr 16 '21 at 10:24
0

This happen to me with a new install of CentOS 9. The problem turned out to be that the /etc/X11/Xresource file permissions had to be changed to include all groups, as root:

# chmod 775 /etc/X11/Xresource
0

To access the console as a normal user, when not logged into the console, you may also need to add root privileges to the config. Doing this for myself fixed the issue:

$ tail -2 /etc/X11/Xwrapper.config 
allowed_users=anybody
needs_root_rights=yes
wryan
  • 111
  • 2