0

Question:

I am trying to run a Python script remotely on my RPi from another python script on my computer.

For now, I have created a local network on my RPi, that my computer can connect to.

I tried to run a subprocess connecting through ssh from my computer:

import subprocess
proc = subprocess.call(["ssh","pi@192.168.4.1","python3 /home/pi/desktop/python_server/python_server.py"],stdout=subprocess.PIPE)
while True:
   line = proc.stdout.readline()
   if not line:
      break
   print("test:", line.rstrip())

But the script doesn't start and I dont get any data back.

How can I connect remotely to the RPi from my computer and start the Python script?

If possible it would be best if this to be done without manually connecting to a local network first. But I dont know if this is possible?

Update:

The process got stuck as it was waiting for me to enter the password to the PI.

How can I avoid entering a password or can Python automatically enter a password to access ssh?

NOTE: I would like to access through ssh from any device, so a ssh key between a single computer and the RPi is not an option.

Frederik Petri
  • 153
  • 2
  • 8

1 Answers1

3

Debug that command from a terminal first, before wrapping it into a Python script.

Chances are, ssh is stuck waiting for you to type the password in order to login.

There's an official Pi guide explaining how to setup passwordless SSH access on a Pi using private/public SSH keys. You can share the same SSH key across several installations.

Dmitry Grigoryev
  • 28,277
  • 6
  • 54
  • 147