As server I got a Raspberry Pi with a display connected by hdmi. From my Windows 10 pc I whant to execute a gui-application on my Pi by ssh, so that the application get's displayed on the Pi's display. The execution should be started by a Python program using paramiko.
If I try the following in the windows-console it works perfectly fine:
- ssh -X user@raspberrypi
- export DISPLAY=:0
- python3 my_gui_app.py
But if I try the following in a python script, it runs without error, but no window pops up at the Pi's screen:
import paramiko
hostname = "raspberrypi"
username = "user"
password = "1234"
command = "python3 my_gui_app.py"
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
client.connect(hostname=hostname, username=username, password=password)
with client.get_transport().open_session() as session:
session.get_pty()
session.request_x11(single_connection=True)
session.set_environment_variable("DISPLAY", ":0")
session.exec_command(command)
# Continuously read the stdout and stderr streams
while True:
if session.recv_ready():
stdout = str(session.recv(4096).decode("utf-8"))
print(stdout, end="")
if session.recv_stderr_ready():
stderr = str(session.recv_stderr(4096).decode("utf-8"))
print(stderr, end="")
# Check if the command has finished executing
if session.exit_status_ready():
break
finally:
client.close()
What am I doing wrong?
On the server, In
/etc/ssh/sshd_config, there will be an option calledAcceptEnvthat allows the ssh client to send environment variables. When setting the environment variable usingsession.set_environment_variable(), the environment variable should also present in/etc/ssh/sshd_configUse the below command to verify:
grep AcceptEnv /etc/ssh/sshd_configIf
DISPLAYvariable is not present, add the it and restart SSHD service.If you can not update/edit the sshd_config of server, update your command