Search code examples
shellsshserverraspberry-piboot

Trying ssh tunel at startup


I need that my server (raspberry/raspbian) execute a shell command at process startup (and not at login).

It is a command to let my server "ssh tunel" to a database :

ssh -fNg -L 3307:127.0.0.1:3306 <myuser>@<remoteIP> -p 22 -i <myprivatekey>

A website hosted on my server (HTTP/apache2) uses this tunel to log to its databse.

No one is logging in to the server, I saw rc.local as a solution but I think it only works by logging in?


Solution

  • Try solution with crontab from here

    #crontab -e
    @reboot  /home/user/test.sh
    

    Note, that if does not wotk from non-super-user set, try with sudo:

    sudo crontab -e
    @reboot  /home/user/test.sh
    

    Of cause, put right command or script after @reboot