30

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?

1 Answer 1

39

Yes, there is. ssh & runs ssh in the background from the very beginning. ssh -f starts ssh in the foreground, allowing it to prompt for passwords etc., and only afterwards ssh puts itself in the background just before executing the requested command.

2
  • 1
    do you have any clue as to why with the new server I would be forced to use the ssh -f rather than the ssh &. In addition to that, it sounds as if ssh -f is a better approach, would you agree to that? Dec 8, 2016 at 3:32
  • Maybe the new system has a newer (or just different) ssh client?
    – AlexP
    Dec 8, 2016 at 6:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .