New user gets the following message "Error: no DISPLAY environment variable specified" when opening graphical applications
- Inicie sesión o regístrese para enviar comentarios
Hello. I created a new user on my laptop, however, when I try to open a graphical application, the terminal prints "Error: no DISPLAY environment variable specified".
The output of 'echo $DISPLAY' an empty line.
Why is it that a newly created user cannot open a graphical application when the "main" user can?
What shall I do so this new user, as well as future users I create, can run graphical application by defaut?
Addition information: I remember having a similar issue when I first setted up Trisquel (I installed Netinstall). I had to run 'export DISPLAY=:0.0' for the user to be able to start abrowser. However, when I run 'export DISPLAY=:0.0' with the newly created user, and then try to open a graphical interface, for example gnome-calendar, I still get the output '(gnome-calendar:8729): Gtk-WARNING **: 16:50:28.592: cannot open display:'
$ uname -a
Linux x220 5.15.0-141-generic #151+11.0trisquel31 SMP Thu Jun 5 11:00:27 UTC 2025 x86_64 x86_64 x86_64 GNU/Linux
How did you create the new user? Are you using the default MATE environment? Is the new user opening a graphical session with the default lightdm greeter (graphical window asking for logging and password)?
I believe I have similar issues when I try to start a X11 program such as xterm in tty3 or somewhere in non-graphical terminal. It seems a little inconsistent. Sometimes the program hangs, sometimes it says something about MIT MAGIC Cookie being in error, sometimes it says the DISPLAY can't connect. I paraphrased of course the errors.
I do have Triskel running fine after deleting my old administrator user.
> How did you create the new user?
I ran: '$ sudo adduser newuser'
> Are you using the default MATE environment?
No. I installed Trisquel netinstall. When I start my system I land on a tty screen, then I can '$ startx' to launch X11. I use awesomeWM as a window manager.
> Is the new user opening a graphical session with the default lightdm greeter (graphical window asking for logging and password)?
No. I switch to the new user by running '$ su - newuser.
Please let me know if you need further information.
> I switch to the new user by running '$ su - newuser.
According to 'man su':
-, -l, --login Start the shell as a login shell with an environment similar to a real login: • clears all the environment variables except TERM and variables specified by --whitelist-environment • initializes the environment variables HOME, SHELL, USER, LOGNAME, and PATH • changes to the target user’s home directory • sets argv[0] of the shell to '-' in order to make the shell a login shell
When you run startx, a number of environment variables are set that are needed to further start applications using Xorg, but as the manual page says, the '-' option will clear most variables. I am not an expert there, but I guess that DISPLAY is not the only concerned variable.
If you want to start applications using Xorg with a different user, you could use 'sudo su newuser' (without '-'). On the computer I have with me, I don't have another normal user, but if I do 'sudo su', I can start an Xorg app, but if I run 'sudo su -', it does not work.
That does not prevent you from having another shell from 'sudo su - newuser' in which you have the full environment of newuser if you want to use it for some other purpose.
I would try without su:
$ sudo -iu newuser
Thanks all for your help.
> When you run startx, a number of environment variables are set that are needed to further start applications using Xorg, but as the manual page says, the '-' option will clear most variables. I am not an expert there, but I guess that DISPLAY is not the only concerned variable.
>
> If you want to start applications using Xorg with a different user, you could use 'sudo su newuser' (without '-'). [...]
Thank you, Avron, for pointing this out, unfortunately this gives me:
mainuser@computer:~$ sudo su newuser
newuser@computer:/home/olduser$ abrowser
Authorization required, but no authorization protocol specified
Error: cannot open display: :0
newuser@computer:/home/olduser$ gnome-calendar --debug
Authorization required, but no authorization protocol specified
(gnome-calendar:2873): Gtk-WARNING **: redacted: cannot open display: :0
> I would try without su: $ sudo -iu newuser
gives me:
olduser@computer:~$ sudo -iu newuser
newuser@computer:~$ gnome-calendar --debug
Authorization required, but no authorization protocol specified
(gnome-calendar:2903): Gtk-WARNING **: redacted: cannot open display: :0
newuser@computer:~$ abrowser
Authorization required, but no authorization protocol specified
Error: cannot open display: :0
Next I tried login in with newuser. I rebooted, landed on the netinstall login interface, entered 'newuser' and its password, landed on a tty session, ran '$ startx' then landed on a session with mwm and xterm (I had installed mwm and xterm a few months ago before I switched to awesomeWM).
To adjust for this, I copied the files .Xauthority and .xinitrc from mainuser to newuser.
I rebooted, logged in with newuser. Now I had a session with awesomeWM.
I was able to start Abrowser and gnonme-calendar (I logged in with newuser).
However, I had 2 problems.
First, it took 60 second for the interface of gnonme-calendar to show up.
$ gnonme-calendar --debug
14:03:17.772712 GLib: [1;32mDEBUG[0m: unsetenv() is not thread-safe and should not be used after threads are created
14:03:42.804151 GLib-GIO: [1;32mDEBUG[0m: _g_io_module_get_default: Found default implementation local (GLocalVfs) for ‘gio-vfs’
14:03:42.864862 dzl-theme-manager: [1;32mDEBUG[0m: Including CSS overrides from resource:///org/gnome/dazzle/themes/
14:03:42.865114 dzl-css-provider: [1;32mDEBUG[0m: Loading css overrides "resource:///org/gnome/dazzle/themes/shared.css"
14:03:42.867784 dzl-theme-manager: [1;32mDEBUG[0m: Loading icon resources from /org/gnome/dazzle/icons/
14:03:42.867936 dzl-theme-manager: [1;32mDEBUG[0m: Including CSS overrides from resource:///org/gnome/calendar/themes/
14:03:42.867969 dzl-theme-manager: [1;32mDEBUG[0m: Loading icon resources from /org/gnome/calendar/icons/
14:03:42.870096 Handy: [1;32mDEBUG[0m: Trying to initialize portal
14:04:07.896104 Handy: [1;32mDEBUG[0m: Settings portal not found: Error calling StartServiceByName for org.freedesktop.portal.Desktop: Timeout was reached
14:04:07.947012 dzl-css-provider: [1;32mDEBUG[0m: Loading css overrides "resource:///org/gnome/dazzle/themes/shared.css"
14:04:07.989075 dzl-css-provider: [1;32mDEBUG[0m: Loading css overrides "resource:///org/gnome/dazzle/themes/shared.css"
14:04:07.994552 (null): [1;32mDEBUG[0m: Created Night Light monitor
14:04:08.26703 e-data-server: [1;32mDEBUG[0m: e_module_load_all_in_directory: Error opening directory “/home/redacted/.local/share/evolution/modules/lib/evolution-data-server/credential-modules”: No such file or directory
14:04:08.366359 GcalWeatherService: [1;32mDEBUG[0m: Starting weather service
14:04:08.435795 GcalCalendarManagementPage: [1;32mDEBUG[0m: Activating GcalCalendarsPage
14:04:08.456037 GcalWindow: [1;32mDEBUG[0m: Updating active date to 2025-06-24 02:04:08 PM +0200
14:04:08.457780 GcalTimeline: [1;32mDEBUG[0m: Adding subscriber GcalWeekView to timeline 0x55a73ba778a0
14:04:08.457870 GcalTimeline: [1;32mDEBUG[0m: Adding subscriber GcalMonthView to timeline 0x55a73ba778a0
14:04:08.457935 GcalTimeline: [1;32mDEBUG[0m: Adding subscriber GcalYearView to timeline 0x55a73ba778a0
14:04:08.597202 GcalWindow: [1;32mDEBUG[0m: Updating active date to 2025-06-24 02:04:08 PM +0200
14:04:08.597709 GcalClock: [1;32mDEBUG[0m: Updating clock time
14:04:08.597741 GcalClock: [1;32mDEBUG[0m: Scheduling update for 52 seconds
14:04:08.600405 GcalTimeZoneMonitor: [1;32mDEBUG[0m: System timezone is redacted/redacted
14:04:08.602226 GcalManager: [1;32mDEBUG[0m: Source Birthdays & Anniversaries (birthdays) connected
14:04:08.602428 GcalCalendarMonitor: [1;32mDEBUG[0m: Spawning thread GcalCalendarMonitor (birthdays)
14:04:08.602905 GcalSearchEngine: [1;32mDEBUG[0m: Adding calendar birthdays to search results
14:04:08.606205 GcalCalendarMonitor: [1;32mDEBUG[0m: Starting ECalClientView for calendar 'Birthdays & Anniversaries'
14:04:08.607123 GcalCalendarMonitor: [1;32mDEBUG[0m: Finished initial loading of calendar 'Birthdays & Anniversaries'
14:04:08.731642 GcalClock: [1;32mDEBUG[0m: Successfully acquired logind DBus proxy
14:04:08.787192 GcalManager: [1;32mDEBUG[0m: Source Personal (system-calendar) connected
14:04:08.787370 GcalCalendarMonitor: [1;32mDEBUG[0m: Spawning thread GcalCalendarMonitor (system-calendar)
14:04:08.787983 GcalSearchEngine: [1;32mDEBUG[0m: Adding calendar system-calendar to search results
14:04:08.791044 GcalCalendarMonitor: [1;32mDEBUG[0m: Starting ECalClientView for calendar 'Personal'
14:04:08.792018 GcalCalendarMonitor: [1;32mDEBUG[0m: Finished initial loading of calendar 'Personal'
14:04:14.110269 GcalWeatherService: [1;33mWARNING[0m: Could not create GCLueSimple: GDBus.Error:org.freedesktop.DBus.Error.AccessDenied: 'org.gnome.Calendar' disallowed, no agent for UID 1002
14:04:17.994739 GcalTimeline: [1;32mDEBUG[0m: Removing subscriber GcalWeekView from timeline 0x55a73ba778a0
14:04:17.994844 GcalTimeline: [1;32mDEBUG[0m: Removing subscriber GcalMonthView from timeline 0x55a73ba778a0
14:04:17.994887 GcalTimeline: [1;32mDEBUG[0m: Removing subscriber GcalYearView from timeline 0x55a73ba778a0
14:04:17.995024 GcalCalendarMonitor: [1;32mDEBUG[0m: Tearing down view for calendar system-calendar
14:04:17.995055 GcalCalendarMonitor: [1;32mDEBUG[0m: Tearing down view for calendar birthdays
Second problem, when I switched to mainuser, I could not open abrowser, I got:
Authorization required, but no authorization protocol specified
Error: cannot open display: :0
What else can I try to troubleshoot?
I'll post further update here if I try something else later.
I created a new user newuser to test what you are doing, I tried starting abrowser from this terminal, then I had, like you:
Authorization required, but no authorization protocol specified Error: cannot open display: :0
Then, as the user that is logged in the graphical session (I open a session with lightdm, not with startx from console), I ran
xhost +si:localuser:newuser
This time, I could start abrowser fine. This xhost command allows the local user newuser to use the display. In the 1990s, I used Sun workstations running some nonfree Unix (but it was easy to use free GNU tools on them), I regularly logged remotely to other machines, and started some app from there with display on my local display, I needed to use xhost to allow this (to allow a different host, not a differet user). It took me a little search to refresh my memory on this. For my curiosity: for which purpose are you trying to run some app from a different user?
About what you did with .Xauthority and .xinitrc: perhaps you want to restore the initial state to avoid any unexpected side effect.
> xhost +si:localuser:newuser
Thank you, Avron. I was able to open a GUI application from the newuser after I ran this command from the user from which I opened a graphical session. I don't know if this setting is persistent; I have not rebooted yet. I'll see.
> This xhost command allows the local user newuser to use the display. [...] It took me a little search to refresh my memory on this.
Thank you for the addtional information and taking the time to look into it. I also looked up the command (and opened the man page) to try to understand what xhost is about and what the command does.
> For my curiosity: for which purpose are you trying to run some app from a different user?
I needed to set up a new mailbox for a project and wanted to use mutt, mbsync, msmtp and notmuch. I already use those as my default. I can add more mailboxes to that configuration (and more From: email addresses to select[1]), but only one default email address[2] in .muttrc, as far as I know. Now that you asked, I am thinking: I could try setting up an alternative .muttrc file and try '$ mutt -F /path/to/alternative/muttrc'. I might not need that new user after all.
This is not all lost --- I also thought it would be useful to set up a new user when I make presentations, in public, with my laptop. Sometimes I am not so comfortable logging in public; I don't want to risk showing the content of my main user.
> About what you did with .Xauthority and .xinitrc: perhaps you want to restore the initial state to avoid any unexpected side effect.
Thank you for mentioning this. I deleted .xinitrc from newuser but I don't think I can revert .Xauthority (if it existed before I copied it from the "main" user?) as I don't have a snapshot/backup of /home/newuser. I can't only delete .Xauthority, I don't know if a new file would be "regenerated" if I do so.
[1] using: macro compose 1 'f^UFirstname Surname' <name at domain>'
[2] set from = name at domain