So I'm at my wits end with this, I'm not a complete n00b with Linux but I know enough to get around etc and change other peoples scripts.
Here's what I am trying to do. Firstly I wanted to enable passwordless ssh into my pi2 using public/private keys but that seems to fail no matter what I do. So, I created an expect script to log into my pi2 whilst specifying the password within the script. Completely unsecure I know but all I'm using ssh for in this case is for forward a specific port (that runs apache2 - Owncloud) through the ssh tunnel so I can access it from the internet. Reason being is that my Elementary OS (Ubuntu 16.04 based) is permanently connected to a VPN and without this port I cannot use my home cloud at work or anywhere away from home. There is no easy way to do a split tunnel with this VPN service, especially if you have a dynamic IP (btw, I'm a network engineer by trade, so this is my strong point).
Now that that's out of the way. The expect script I'm running is as follows.
#!/usr/bin/expect >set timeout 20 set ip [lindex $argv 0] set user [lindex $argv 1] set password [lindex $argv 2] spawn ssh -fN -R [remote port]:localhost:[local port] "$user\@$ip" expect "firstname.lastname@example.org's password:" send "$password\r"; interact
Then I specific the following in terminal.
/usr/local/bin/ssh.exp [ip address] [username] [password]
This works perfectly fine and I can execute the script after I've logged in.
I'd like to get this working automatically on boot, and so far nothing has worked. Adding this to crontab with @reboot fails, adding this to rc.local also fails. I'm wondering whether it's because it trys to run it in the foreground or because its an expect script, not bash.
Completely at a loss here people, some advice would be greatly appreciated. On a side note, if I can get passwordless ssh working at the same time that would be great.