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?

6
  • I am not sure whether I understand your question correctly. Might these two questions, plus answers, be of help to you? - askubuntu.com/questions/1066721/… - askubuntu.com/questions/1061354/…
    – Jan
    Sep 23, 2018 at 9:23
  • 1
    I don't see how either of those questions would be relevant. They both discuss headless servers. I am connecting to an Ubuntu Desktop install with a currently active local session running on a physically connected monitor. I want to poll the local session for the current resolution of the physically connected monitor.
    – Daniel
    Sep 23, 2018 at 14:30
  • I thought it could be relevant as you describe that "there is no display connected to my remote SSH session."
    – Jan
    Sep 24, 2018 at 15:23
  • I see, but both of your links are about completely headless servers with no physical display, and the solutions seem to revolve around connecting to a "virtual" display. I need to connect to the physically connected display to poll its current resolution.
    – Daniel
    Sep 24, 2018 at 16:16
  • what are you attempting to achieve ? to launch a UI app on remote box and display locally ? Sep 26, 2018 at 16:38

2 Answers 2

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.

2
  • This sort of works. It looks like it is giving me available resolutions for the connected device, but it doesn't give me the actual, current resolution. This probably works for my purposes as I can assume the highest available resolution is the one currently in use, but it doesn't really strictly or definitively answer my question.
    – Daniel
    Sep 22, 2018 at 20:45
  • You edited your post several times since I replied. I haven't tried the 2. solution yet.
    – Daniel
    Sep 23, 2018 at 14:31
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .