1

I have a Raspberry which establish a connection to a remote machine, via ssh, using a SSH Keypair, which allow it to access without prompting a password.

My question is this:

How I can do to establish a SSH-connection from the Raspberry to a default remote machine, which has a static IP, and execute a remote command, on Raspberry's boot? I've tried a lot of solutions, but none of these works!!

1) adding my script to /etc/init.d and then update-rc.d myscript defaults

2) adding into /etc/rc.local file

3) adding into /home/pi/.bashrc file

-----TO EXPLOIT THE AUTOMATIC CONNECTION OF PI TO WIFI_____

4) adding into /etc/network/if-up.d

5) adding by "post-up" command into interfaces file

I have ever fail. This below is my script:

#! /bin/sh
ssh remotemachine@ip-address touch success
0

Maybe give it a go with cron.

crontab -e

Add a line:

@reboot ssh remotemachine@ip-address touch success

If you want to allow some time for the system (and interface) to come online:

@reboot sleep 60 && ssh remotemachine@ip-address touch success

The interface post-up execution makes more sense, cron is easier but not ideal. For Raspberry experimentation it should be good enough.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.