3

I'm running Ubuntu 18.04.1 LTS Desktop.

I'm connecting to the desktop via remote SSH session.

I'm trying to get the current resolution for the currently active local session.

I found these seemingly relevant questions:

However, xdpyinfo returns the following error:

xdpyinfo:  unable to open display "".

and xrandr returns a similar error:

Can't open display

I'm assuming this is because there is no display connected to my remote SSH session. I've tried switching (su) to the same user as the local session, but the error is the same - I assume for the same reason: no display related to that SSH session.

So, I tried the suggestions from my third link above.

$ export DISPLAY=:0
$ xdpyinfo
No protocol specified
xdpyinfo:  unable to open display ":0"

and

$ xrandr --display :0
No protocol specified
Can't open display :0

How can I poll the display on the active local session for resolution (dimension) info from a remote SSH session?

Daniel
  • 251
  • 1
  • 3
  • 8

2 Answers2

5

1. You can try this command

cat /sys/class/drm/*/modes

or to get more info

grep . /sys/class/drm/*/modes

To get the status of each device, type

grep . /sys/class/drm/*/status

2. Or read the monitor screen data

Extended Display Identification Data (EDID): This standard defines data formats to carry configuration information, allowing optimum use of displays.

A monitor typically supports multiple resolutions and refreshrates. Of course someone will prefer the maximum (physical) one.

To read this monitor data, try one of these solutions:

  • edid-decode

    If not installed, type

    sudo apt install edid-decode
    

    Then read the edid file

    edid-decode /sys/class/drm/card0-eDP-1/edid
    
  • read-edid

    Install with

    sudo apt install read-edid 
    

    Then read via i2c the screen monitor data and parse it

    sudo get-edid | parse-edid
    
  • Hexdump the edid data

    In case edid-tools are not installed, you can dump the edid hex-file, e.g.:

    hd /sys/class/drm/card0-eDP-1/edid
    

    To encrypt this hex file take a look at wiki or download the edid specifications.

abu_bua
  • 11,313
0

X-Windows has a command that gives you information about a display. You can start it with:

xdpyinfo | less

When running via SSH, though, you will not have access to X-Windows unless you use the -X option and the server allows remote connections through ssh (which is the case by default on Ubuntu).

ssh -X <other-desktop>

If it looks like the ssh daemon does not let you connect that way (you'll be able to get the ssh session, but with an error saying X11 is not available) then edit the ssh server settings on your destination desktop:

sudo vim /etc/ssh/sshd_config

and search for X11 and make sure the following is not commented out (no starting # character) and that it says yes:

X11Forwarding yes

If you had to change that, restart the ssh daemon:

sudo systemctl restart sshd

If you restarted sshd, make sure to reconnect (Ctrl-D to exit and then ssh -X .... again).

Once connected and the X-Windows error is out of the way, in your ssh session you can do:

DISPLAY=:0 xdpyinfo | less

This gives you the info about display :0 which, in most likelihood, is the display of the user currently running (if you have many users, you may have multiple screens so :0 may not be correct).

Search the output for:

dimensions:    3840x2160 pixels (1016x572 millimeters)

and now we know the resolution. This example shows a 4K display.

So I think all you were missing was the -X on the ssh -X ... command.

Alexis Wilke
  • 2,787