papallot
Posts: 10
Joined: Fri Aug 24, 2018 2:21 pm

Using feh over ssh connection

Sun Jul 14, 2019 12:49 pm

Hello,

I am trying to open a picture in my raspberry pi 3b+ from my computer (I have linux mint installed).

It is very basic:
-I connect to the raspberry: -I introduce my password
-Once I am in the raspberry, I execute feh:

Code: Select all

feh /home/pi/mypicture.jpg
the following error apperars: "feh ERROR: Can't open X display. It *is* running, yeah?"

Doing some readying, I can solve it by typing on the command line

Code: Select all

export DISPLAY=:0
After this, it works perfectly.

Is there a possibility to do that automatically? I have tried to put it in the autostart file but it doesn't work

Thanks a lot

User avatar
scruss
Posts: 2252
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Using feh over ssh connection

Sun Jul 14, 2019 1:40 pm

If you do it should set up DISPLAY correctly
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

papallot
Posts: 10
Joined: Fri Aug 24, 2018 2:21 pm

Re: Using feh over ssh connection

Sun Jul 14, 2019 3:09 pm

Thanks for the answer.

I have tried with that, but it still doesn't work.

After logging in to my raspi as ssh -X 192.168.1.61, if I write "printenv", I see that currently the variable "DISPLAY" is set to "localhost:10"

When I run feh, nothing happens on the screen and the terminal is stuck. I can carry on with ctrl+z.

Thanks!

User avatar
rpdom
Posts: 14412
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Using feh over ssh connection

Sun Jul 14, 2019 3:51 pm

Are you trying to get the image to display on the monitor connected on the Pi, not on the PC you're using for ssh?

ssh -X makes the Local display the one to output to.

To get it to display on the Pi you'll need to set the DISPLAY variable once logged in.
Yes, I do block a very small number of people.

No, I'm not going to name them. That would be childish.

papallot
Posts: 10
Joined: Fri Aug 24, 2018 2:21 pm

Re: Using feh over ssh connection

Sun Jul 14, 2019 4:55 pm

Yes, that is correct. I am displaying the images on a screen connected to the pi with hdmi.

How can I change the variable automatically?

Thanks a lot

User avatar
scruss
Posts: 2252
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

Re: Using feh over ssh connection

Sun Jul 14, 2019 6:01 pm

Untried - and possibly in the wrong config file - but add the following near the end of your ~/.bashrc file:

Code: Select all

if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
	if [ -n "$DISPLAY" ]; then
		export DISPLAY=:0
	fi
fi
This should set the display to use the Raspberry Pi's monitor over ssh, but still respect a remote ssh -X request if you do ever want to display things locally.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

papallot
Posts: 10
Joined: Fri Aug 24, 2018 2:21 pm

Re: Using feh over ssh connection

Sun Jul 14, 2019 7:55 pm

Awesome, that kind of worked!!

I had to remove the inner if because, I don't know why, the condition [ -n "$DISPLAY" ]; it goes false.

Code: Select all

if [ -n "$SSH_CLIENT" ] || [ -n "$SSH_TTY" ]; then
	export DISPLAY=:0
fi
I tried that and everything works perfectly. Thanks a lot!!

If you don't mind, I would like to ask another related question:

I need to make the call from another raspberry and I am doing it inside another python script:

Code: Select all

import sys
import subprocess

subprocess.call("ssh [email protected] feh /home/pi/mypicture.jpg",shell=True)
Apparently it doesn't work, the same error appears. I have done some debugging and the file ~/.bashrc is not being run.

thanks again

klricks
Posts: 6429
Joined: Sat Jan 12, 2013 3:01 am
Location: Grants Pass, OR, USA
Contact: Website

Re: Using feh over ssh connection

Mon Jul 15, 2019 12:58 pm

Have you tried using the DISPLAY=:0 directly from ssh prompt?

Code: Select all

DISPLAY=:0 feh /home/pi/mypicture.jpg
Unless specified otherwise my response is based on the latest and fully updated Raspbian Buster w/ Desktop OS.

Return to “Beginners”