Export display in linux

How do I automatically set the $DISPLAY variable for my current session?

I see that $DISPLAY is set to localhost:0.0 if I am running over a vnc server this may not be correct, is there a way to automatically set it in my login script?

questions like this are more about operating systems than programming and serverfault.com is where they go.

It seems when vncserver started, the DISPLAY variable is automatically set in the new vnc session, at least this works for me.

You should describe what machine your are logging into, and where the vnc server(s) are running. Any shells created in a vncserver environment would already have the correct DISPLAY variable. It sounds like you are remote logging into a remote host and trying to start apps on an already running X server. Your login script doesn’t know which vnc server it should connect to any more than we do.

5 Answers 5

Here’s something I’ve just knocked up. It inspects the environment of the last-launched «gnome-session» process (DISPLAY is set correctly when VNC launches a session/window manager). Replace «gnome-session» with the name of whatever process your VNC server launches on startup.

PID=`pgrep -n -u $USER gnome-session` if [ -n "$PID" ]; then export DISPLAY=`awk 'BEGIN $1=="DISPLAY" ' /proc/$PID/environ` echo "DISPLAY set to $DISPLAY" else echo "Could not set DISPLAY" fi unset PID 

You should just be able to drop that in your .bashrc file.

login, switch user & login into another account, switch back to first account and «last launched gnome-session» is not the active one any more.

I had to change your awk line to: export DISPLAY=$(cat /proc/$PID/environ | strings | awk ‘BEGIN $1==»DISPLAY» ‘) Then it worked.

Also, I changed pgrep to ‘gnome-session|xfdesktop’ , to include xfce desktops. Full command is now: PID=$(pgrep -n -u $USER ‘gnome-session|xfdesktop’)

do you use Bash? Go to the file .bashrc in your home directory and set the variable, then export it.

DISPLAY=localhost:0.0 ; export DISPLAY

you can use /etc/bashrc if you want to do it for all the users.

You may also want to look in ~/.bash_profile and /etc/profile

function get_xserver () < case $TERM in xterm ) XSERVER=$(who am i | awk '' | tr -d ')''(' ) XSERVER=$ ;; aterm | rxvt) ;; esac > if [ -z $ ]; then get_xserver if [[ -z $ || $ == $(hostname) || \ $ == "unix" ]]; then DISPLAY=":0.0" # Display on local host. else DISPLAY=$:0.0 # Display on remote host. fi fi export DISPLAY 

if i put this in my bashrc it wont work with vncserver because it creates other displays like localhost:1.0 etc so i need a little more generic solution.

I’m guessing here, based on issues I’ve had in the past which I did solve:

  • you’re connecting to a vnc server on machine B, displaying it using a VNC client on machine A
  • you’re launching a console (xterm or equivalent) on machine B and using that to connect to machine C
  • you want to launch an X-based application on machine C, having it display to the VNC server on machine B, so you can see it on machine A.
Читайте также:  Linux find newer file

I ended up with two solutions. My original solution was based on using rsh. Since then, most of our servers have had ssh installed, which has made this easier.

Using rsh, I put together a table of machines vs OS vs custom options which would guide this process in perl. Bourne shell wasn’t sufficient, and we don’t have bash on Sun or HP machines (and didn’t have bash on AIX at the time — AIX 5L wasn’t out yet). Korn shell wasn’t much of an option, either, since most of our Linux boxes don’t have pdksh installed. But, if you don’t face these limitations, you can implement the idea in ksh or bash, I think.

Anyway, I would basically run ‘rsh $machine -l $user «$cmd»‘ where $machine, of course, was the machine I was logging in to, $user, similarly obvious (though when I was going in as «root» this had some variance as we have multiple roots on some machines for reasons I don’t fully understand), and $cmd was basically «DISPLAY=$DISPLAY xterm», though if I were launching konsole, for example, $cmd would be «konsole —display=$DISPLAY». Since $DISPLAY was being evaluated locally (where it’s set properly), and not being passed literally across rsh, the display would always be set correctly.

I also had to make sure that no one did anything silly like reset DISPLAY if it was already set.

Now, I just use ssh, make sure that X11Forwarding is set to yes on the server (sshd_config), and then I can just ssh to the machine, let X commands go across the wire encrypted, and it’ll always go back to the right place.

Источник

How to export display in linux

I don’t see solution to my problem in this thread How to make exported shell variables permanent? Question: How to export a keyboard config with the display in linux (with Exceed client app) please ?

Why can i export the display from linux to linux?

local machine

[mukesh@centos ~]$ xhost 192.168.4.200 192.168.4.200 being added to access control list 

remote VM machine

[mukesh@centos ~]$ ssh user@192.168.4.200 user@192.168.4.200's password: Last login: Fri Jul 7 02:38:07 2017 [user@labipa ~]$ DISPLAY=192.168.1.3:0.0;export DISPLAY [user@labipa ~]$ firefox Error: cannot open display: 192.168.1.3:0.0 [user@labipa ~]$ su - Password: Last login: Fri Jul 7 02:47:53 EDT 2017 on pts/1 [root@labipa ~]# cat /etc/ssh/sshd_config | grep X11F X11Forwarding yes # X11Forwarding no 

Also, as per http://www.softpanorama.org/Xwindows/Troubleshooting/can_not_open_display.shtml on remote machine

[root@labipa ~]# netstat -tulpen | grep "\(177\|6000\)" tcp 0 0 0.0.0.0:6000 0.0.0.0:* LISTEN 0 50364 1512/Xorg tcp6 0 0 . 6000 . * LISTEN 0 50363 1512/Xorg udp 0 0 0.0.0.0:177 0.0.0.0:* 0 48805 1476/gdm contents of /etc/gdm/custom.conf [security] DisallowTCP=false [xdmcp] Enable=true 

If X11 forwarding is enabled in both the client and the server , ssh will automatically set up the DISPLAY variable (to a local proxy). You don’t need to set it, and especially not directly to the machine’s IP address; that will completely bypass the ssh mechanism. Use echo $DISPLAY to verify the display is set by ssh .

If you only enabled X11 forwarding on the server (as shown), and don’t want to enable it generally, use ssh -X to also enable it in the client on a per-use base.

Читайте также:  Artix linux установка yay

How to export DISPLAY onto another linux host’s Xserver, export DISPLAY=:0.0 But I want to export display onto another linux host. export DISPLAY=:0.0 I am running opensuse and I think Xorg should do the job. But I could not figure out what exactly needs to be done. If there are any other Xming equivalent packages for … Usage examplexhost +Feedback

Export DISPLAY with azerty keyboard

How to export a keyboard config with the display in linux (with Exceed client app) please ?

export DISPLAY=IP setxkbmap fr pycharm 

The pycharm export in exceed is working but the setxkbmap fr doesnt work. The keyboard in pycharm is in qwerty whereas my keyboard on my server is in azerty (which I need in pycharm). Thanks

I’m using RHEL 7.9. I’m root. Maybe it is exceed side, config wizard ? idk

Answer : Right click on exceed mini windows on task bar then Tools > Xconfig > Input Devices / Keyboard input

However, I didn’t find how to activate Alt Gr key

Why I can’t export the Linux DISPLAY?, You don’t get to specify the IP address of either computer. You need to export the display that is tunnelled through SSH, and that means export DISPLAY=localhost:x.y, which should have been done for you automatically when you connect using ssh -X. Share. Improve this answer. answered Jun 16, 2015 at …

Xvfb: export display permanently

I have recently set up Xvfb on Centos 7 machine.

It is working absolutely fine.

Only problem is that if I quit putty session (remote access) it would keep running Xvfb in background but display will be gone.

So next time when I take remote access via putty first I have to type export DISPLAY=:99 again, then I start my tests.

How can I make it permanent? I don’t see solution to my problem in this thread How to make exported shell variables permanent?

Update: .profile contents:

export M3_HOME=/home/aditi.a/apache-maven-3.5.4/bin export PATH=$PATH:$M3_HOME export JMETER_HOME=/home/aditi.a/apache-jmeter-5.0/bin export PATH=$PATH:$JMETER_HOME export JAVA_HOME=/usr/java/jdk1.8.0_192-amd64 export PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export DISPLAY=:99 

echo variables output:

$ echo $JAVA_HOME /usr/java/jdk1.8.0_192-amd64 $ echo $M3_HOME /home/adit.a/apache-maven-3.5.4/bin $ echo $DISPLAY $ 
$ ps -p $$ PID TTY TIME CMD 30678 pts/14 00:00:00 sh 

I second what @JigglyNaga said, there is nothing wrong/missing after looking at your .profile file.

Only thing I would suggest copy same contents at

/home/aditi.a/.profile and .bashrc
/root/.profile and .bashrc files

How can I export DISPLAY from a Linux terminal to a, On the bash startx — -listen tcp & export DISPLAY=192.168.1.4:0.0 xhost + 192.168.1.20 On the X term launcheed by running cmd in step 3 do the same as in step 4 an 5 On the xterm ssh -Y Either use putty. IP address docker host 192.168.1.20 and ssh port 22 Enable port forward SSH —> X11 tick the enable …

How to clear export DISPLAY=some ip address

I want to clear export DISPLAY=My IP Address that I had given. It has botched up my X settings, so now I just want it to be reset like normal. How to clear this export parameter. Simple set DISPLAY= doesn’t work.

Please tell me how to achieve this.

Читайте также:  Kali linux uefi install

Usually you should have it set like this:

export DISPLAY="localhost:0.0" 

As others have mentioned, knowing the shell you’re using might help.

Otherwise, have you tried simply using unset ? The exact command would be unset DISPLAY , for this specific variable.

in bash should clear any value

Centos — Why can i export the display from linux to linux?, Use echo $DISPLAY to verify the display is set by ssh. If you only enabled X11 forwarding on the server (as shown), and don’t want to enable it generally, use ssh -X to also enable it in the client on a per-use base. Share Improve this answer answered Jul 7, 2017 at 8:10 dirkt 29.4k 3 37 69 Add a comment

Источник

How can I export DISPLAY from a Linux terminal to a Windows PC?

Exporting display from a Linux terminal to a Linux desktop is easy; you do the following: On 192.168.90.121 (localPC):

export DISPLAY=192.168.90.121:0.0 
firefox

The Firefox window appears on my localPC. In the above case both PCs are Linux. Can I similarly export the Linux display to a Windows PC? In the above example, localPC would be Windows and remotePC would be Linux.

2 Answers 2

Yes you can, if you install an X server on your Windows computer. There are a number of commercial choices (I used Starnet X-Win32 some time ago), and a couple of open source ones, like Cygwin/X and XMing. It’s not as painless as Linux to Linux (or another Unix derivative that natively uses X11) but the result is quite acceptable and usable.

Use Cygwin. i Use ubuntu on docker container but this will work easily without containired Ubuntu , i.e. full blown ubuntu machine on the same lan as windows machine.

Just ignore the host container IP term. Host conatiner IP == Ubuntu Machine IP.

Ubuntu host container IP 192.168.1.20 Remote windows machine on same LAN IP 192.168.1.4

On ssh ubuntu conatiner : sudo vim /etc/ssh/sshd_config : restart ssh server onubuntu X11UseLocalhost no

On remote windows machine running Cywin X server

  1. Open cgywin bash 2.cd /cydrive
  2. On the bash startx — -listen tcp &
  3. export DISPLAY=192.168.1.4:0.0
  4. xhost + 192.168.1.20
  5. On the X term launcheed by running cmd in step 3 do the same as in step 4 an 5
  6. On the xterm ssh -Y
  7. Either use putty. IP address docker host 192.168.1.20 and ssh port 22
  8. Enable port forward SSH —> X11 tick the enable port forward. In the same tab use the Display location remote windows machine 192.168.1.4:0.0 on which the remote Ubuntu container will throw its display 10.Click connect, enter credentials and run an xll-GUI like xeyes
  9. Two eyea will appear on 192.168.1.4:0.0 remote windows machine not using linux display.
  10. So no need to install separate full blown X11 server on Ubbuntu keeping the conatiner lightweight
  11. Oh yes, for xeyes you need to install some x-11 GUI apps, sudo apt-get install x11-apps
  12. Make sure u tyoe in xeyes & so that it does not block the shell.
  13. On the Xterminal you can do the same as in putty.ssh -Y wasadmin@192.168.1.20. The -Y flag is required for trusted port forwarding.Once logged in type xeyes &

Источник

Оцените статью
Adblock
detector