I have a process that expects an ssh tunnel connection to execute correctly and I have been using the following command:
ssh -L localhost:3306:127.0.0.1:3306 username@<mysql-machine-ip-address> -N &
I have ran this successfully for 8 months, recently our hosting provider had to make hardware changes to update our machine, and upgraded our machine with a new kernel for Ubuntu. It went from 4.8.3-x86_64-linode76 to 4.8.6-x86_64-linode78.
After a bunch of trouble shooting we've had to update the command to this:
ssh -L localhost:3306:127.0.0.1:3306 username@<mysql-machine-ip-address> -fN
When researching the ssh documentation the -f parameter
Requests ssh to go to background just before command execution.
This is useful if ssh is going to ask for passwords or
passphrases, but the user wants it in the background. This
implies -n. The recommended way to start X11 programs at a
remote site is with something like ssh -f host xterm.
When researching the bash command for "&"
Place a process into the background (see multitasking in "Intermediate Use Of >The UNIX Operating System").
Is there fundamentally any difference in these 2 commands?
Best Answer
Yes, there is.
ssh &
runsssh
in the background from the very beginning.ssh -f
startsssh
in the foreground, allowing it to prompt for passwords etc., and only afterwardsssh
puts itself in the background just before executing the requested command.