EmilySeville7cfg · 2022-06-25 16:08
I've created a new user via `adduser` command switched to it. When I start `emacs` I obtain:
```No protocol specified
Display :0 unavailable, simulating -nw
```
Is it normal? Why it happens?
mattias_jcb · 2022-06-25 16:29
I don't remember entirely how it works but I'd read the man page for xhost if this happened to me. It's got something to do with the DISPLAY variable and/or xhost. Somehow your new user doesn't have access to X
nderflow · 2022-06-25 16:42
Use `sudo -E` to switch to the new user, to preserve the value of DISPLAY.
xtifr · 2022-06-25 23:49
The new user doesn't know how to find your X11 session, and, more importantly, wouldn't have permission to write to it, even if it could find it!
There are several possible solutions, which vary in both difficulty and security.
1. Use Emacs's built-in remote access system, TRAMP. This is the most Emacs-y solution.
2. Use `ssh -X` to log into the other user's account.
3. Start a new GUI session as the new user.
4. Use `xhost` and set the `DISPLAY` variable. (Not recommended!)
Option 4 is the old-fashioned solution, but it's generally considered somewhat insecure, so I'll ignore it for now. Option 3 might be the simplest solution, but I'm going to assume it's not what you're after. So I'm just going to discuss the other two.
The `ssh` solution uses ssh's built-in X11 forwarding capabilities, which handle everything. It has the advantage of working with *all* X11 programs, not just Emacs. It has the disadvantage that everything has to travel through a single encrypted pipeline, which is not super-efficient. Also, you have to run two copies of Emacs. You can either just log in as the remote user using `ssh -X user@localhost` and then type emacs at the command-line, or you bypass the command line with `ssh -X user@localhost emacs`.
The TRAMP solution only works with Emacs, of course, but it's fast and efficient, and has the *huge* advantage that you're using *your* copy of Emacs with all *your* settings, so you don't have configure Emacs for the new user. Just open the file with magic name `/su:user@:path/to/file` or `/sudo:user@:path/to/file`, where "user" is the new username, and, of course "path/to/file" is the pathname of the file you want to edit.