Taking screenshot via ssh

3

1

Is there a way to take a screenshot of what is on screen by being remotely logged on that machine with ssh?
Vnc is no good, since AFAIK it cannot take ownership of an existing X session.

mbq

Posted 2010-12-22T13:33:31.367

Reputation: 727

as the user owning the x11-session you are interested in? – akira – 2010-12-22T14:13:32.867

@akira Yes. (some more characters) – mbq – 2013-11-18T16:32:49.933

Answers

11

You might want to try this:

xwd -out screenshot.xwd -root -display :0.0

It will save the screenshot to screenshot.xwd which GIMP should be able to open. Check out the xwd man page here: http://linux.die.net/man/1/xwd

BloodPhilia

Posted 2010-12-22T13:33:31.367

Reputation: 27 374

2@akira There are plenty of reasons you'd want to do this other than to spy. Right now I'm connected to my work computer over SSH and trying to figure out why my code editor is using 200% CPU usage. There isn't anyone using the computer - but I left the editor open when I locked the machine. So maybe a screenshot will help diagnose the problem. – AnnanFay – 2017-01-15T15:55:59.170

any screenshot program will do: scrot, import (from imagemagick) etc. you just point it to the right $DISPLAY (or -display or --display or --dpy .. thats why i prefer $DISPLAY) and thats it. the main question remains unanswered: wants OP to capture a session (aka spy) on someone else? – akira – 2010-12-23T07:27:52.253

1

Assuming you have ImageMagick installed on the remote and local machine, the X server on the remote machine is running as the user you are connecting with, you can take a screenshot remotely and display it on your local X server like this:

ssh user@example.com "DISPLAY=:0 import -window root -" | display

This is very convenient as you don't need to copy any temporary files.

Florian

Posted 2010-12-22T13:33:31.367

Reputation: 111