I've tried to write a very little script in order to connect to my raspberrypi as follows:
#!/usr/bin/python
#connect to raspberry pi -- ethernet
import os
os.popen('ssh -l pi 169.254.249.166')
but it returns just immediately prints the prompt for my password three times -- I can't write anything and I don't know why.
After the request I just can push Intro and it returns to me to the prompt.
The output of the script is as follows:
xxx@xxx:~$ python connect_raspberry.py
xxx@xxx:~$ pi@169.254.249.166's password:
xx@xx:~$ pi@169.254.249.166's password:
Permission denied, please try again.
pi@169.254.249.166's password:
Permission denied, please try again.
pi@169.254.249.166's password:
Permission denied (publickey,password).`
Why doesn't the script, or maybe the Raspberry as I guess from the prompt, let me type the password? It just answers "permission denied", but I type nothing.
What I really try to write is to run a script in konsole: python code.py
and that it returns to me to the Rasp prompt (I suppose I should write the password into a variable but first, I try to log in automatically and write the password):
xx@xx:~$ python code.py
pi@169.254.249.166's password:
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Sep 17 23:16:57 2017 from peces.local
pi@raspberrypi:~ $
On the other hand, any help about how to write the password into a variable in the Python script to login automatically, I mean:
xxx@xxx:~$ python connect_raspberry.py
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Sep 17 23:16:57 2017 from peces.local
pi@raspberrypi:~ $
For the latter, I don't understand so well the ssh
command's -f
option
(this flag implies the -n
flag).
I am a little confused about if it is what I need for logging in automatically.