SSH on boot via rc.local
I am trying to ssh into a server on boot. I have written a simple bash script to perform this action. The script works fine if I run it from the command line, issue is with rc.local. The script /home/RPi_1/autoCon.sh is below:
#!/bin/bash sleep 20 while true; do ssh [email protected] \ -R 22:localhost:22 -N -o ServerAliveInterval=10; \ sleep 5; done
/home/RPi_1/autoCon.sh > /home/RPi_1/autossh.log 2>&1 & exit 0
The autossh.log file is filled with this error: Host key verification failed.
I have two users on the my Raspberry Pi, pi and RPi_1. I think I have identified the issue being that when rc.local is being executed it is executed as root or pi? Thus, when the key is being searched for it is looking in the wrong directory? The key for the server is in /home/RPi_1/.ssh/
Similar issue at: https://www.raspberrypi.org/forums/viewtopic.php?t=261103
3B running Raspbian GNU/Linux 8 (jessie)