When using screen, you will have to copy the required environment variables manually.
Detach from the screen session, run echo $DISPLAY
and copy the value.
Now reattach and run export DISPLAY="copied value"
.
When you create a Screen session, the screen server automatically inherits a copy of the current environment, which is further inherited by the shells or other processes that you start in new Screen windows inside the session.
xterm (DISPLAY=":0")
└── bash (DISPLAY=":0")
└── screen (client) (DISPLAY=":0")
└── SCREEN (server) (DISPLAY=":0")
├── irssi (DISPLAY=":0")
├── mutt (DISPLAY=":0")
└── bash (DISPLAY=":0")
When you connect over SSH with X11 forwarding enabled, the SSH server sets the $DISPLAY
environment variable pointing to your X11 server.
However, when you reattach to a Screen session, the processes running inside that session will not see it; they are still holding copies of the old environment.
sshd (DISPLAY="localhost:12")
└── bash (DISPLAY="localhost:12")
└── screen (client) (DISPLAY="localhost:12")
SCREEN (server) (DISPLAY=":0")
├── irssi (DISPLAY=":0")
├── mutt (DISPLAY=":0")
└── bash (DISPLAY=":0")
This is because a process is not allowed to update environments of other processes; only of itself. Even though the screen client process has the new environment, it cannot give it to the screen server; the protocol used by Screen simply does not have such a function.
Some other multiplexers, such as tmux, allow clients to send a copy of its environment to the server upon reattaching. This is not completely effective; it only allows newly opened tmux windows to inherit the new environment, but still cannot do anything about already running windows.
For a somewhat less manual process, check out http://superuser.com/questions/1028585/
– xpt – 2016-01-23T19:07:12.050