2

If I run xrandr from a terminal in the X session I can see the names of different outputs available on the system. For example, I get something like this:

Screen 0: minimum 320 x 200, current 1440 x 900, maximum 8192 x 8192
VGA disconnected (normal left inverted right x axis y axis)
LVDS connected (normal left inverted right x axis y axis)
    1440x900       59.9*+
    1280x854       59.9  
    1280x800       59.8  

That's great, but it only works if I am on the X session either physically in front of the computer or via Remote Desktop (VNC). How can I get these same names remotely via SSH instead? I probably wouldn't be using xrandr for it, but then what should I use?

With the above example, what I would like to get from SSH is the "VGA" and "LVDS" values.

user195574
  • 21
  • 1
  • 2

2 Answers2

2

If you connect through ssh, you could very well not even having an X session running. Even if you have it, the ssh session is not connected to any of them by default... you can even login via ssh to an user different from the one that has the X session opened.

So for example if I ssh to my remote machine I have:

(0)pern:~% xrandr --current
Can't open display 

So I have to find if an X session is running and who is connected:

(0)pern:~% w
 01:57:06 up 10 days,  9:56,  4 users,  load average: 0.12, 0.17, 0.13
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
romano   tty7     :0               08Nov13 10days  1:29m  6.95s gnome-session -
romano   pts/2    :0               08Nov13 10days 23.67s 23.67s /home/romano/bi
romano   pts/0    xxx.xx.xxx.xxx   01:56    2.00s  0.08s  0.00s w
romano   pts/3    :0               08Nov13  6:48m  0.08s  0.08s zsh

Hmmm... let's see the capability of display :0, given that I am logged as the same user and so I have the permissions:

(1)pern:~% xrandr --current -display  :0
Screen 0: minimum 320 x 200, current 1680 x 1050, maximum 8192 x 8192
DIN disconnected (normal left inverted right x axis y axis)
DVI-0 connected 1680x1050+0+0 (normal left inverted right x axis y axis) 430mm x 270mm
   1680x1050      59.9*+
   1600x1200      60.0  
   1280x1024      75.0     60.0  
   1024x768       75.1     72.0     70.1     60.0  
   832x624        74.6  
   800x600        72.2     75.0     60.3     56.2  
   640x480        72.8     75.0     66.7     60.0  
   720x400        70.1  

Notice that all this will work if the user on the non graphic session has sufficient rights to the server. Basically, it needs to be the same user that started the X server (and sometime, do to .Xauthority, not even in that case); to have it working anytime, you should do xhost + on the server (but this has big security risks).

Rmano
  • 31,947
  • i this is not ssh, from CTRL-ALT+F2, xrandr --verbose --current --display :0 and variations such as --display localhost:0 results in cant open display. – rjt Jan 19 '16 at 20:07
  • @rjt Did you try with xrandr -display :0.0? It works here. – Rmano Jan 19 '16 at 20:39
  • :0.0 and :0 work using gnome-terminal but neither work from CTRL-ALT+F2. tty text only terminal. – rjt Jan 19 '16 at 20:59
  • @rjt Works here without problem. Are you logged in the VC with the same user that is running X? Have you tried to issue an xhost + on the X server? – Rmano Jan 19 '16 at 21:16
  • i was sudoed up from that user to root. Without sudo, it did work. – rjt Jan 20 '16 at 14:03
  • @rjt Why do you expect Xorg displays to be active on tty2? tty2 is not Xorg. If you switch to any tty that is not running Xorg, then you won't get any Xorg displays. – bain Jan 20 '16 at 16:26
  • @bain, i do not expect it to be active, but it is just text based information we are after. xrandr --display :0 does work from tty2.. – rjt Jan 20 '16 at 18:48
  • @bain, think all those times that graphics has crashed but ssh or tty2 still works. – rjt Jan 20 '16 at 18:49
  • $DISPLAY is only exported in an X session. On tty2 there is no X session so the variable isn't set. But if there is a display running on another terminal with the same user id and you manually specify a display xrandr will still work because it can access the display socket in /tmp/.X11-unix/ – bain Jan 20 '16 at 19:00
1

I've already covered how to list displays in a previous life, that should allow you to iterate each X display and show available outputs

w -hs | awk '{print $3}' | sort -u | xargs -I% xrandr -display %

I've no idea if you need to loop displays, but that should work nonetheless.

Oli
  • 293,335
  • 1
    This didn't work. w doesn't really show a list of enabled display ports. Remember, I am looking for the "VGA" and "LVDS" bit. – user195574 Sep 24 '13 at 03:12