I have a command to forward a port from my computer to a server, as follows:

ssh -L 8000:localhost:8888 myserver.com

I would like to run this command in background. I don't need to enter user and password since I already setup a public key.

I tried adding & at the end, as follows: ssh -L 8000:localhost:8888 myserver.com& But, I got the following error:

[1]  + 30825 suspended (tty output)

I tried also nohup , as follows:

nohup ssh -L 8000:localhost:8888 myserver.com&

but the port is not forwarding.

Finally, I tried ssh -f , as follows:

ssh -L 8000:localhost:8888 myserver.com

and, I got the following error:

Cannot fork into background without a command to execute.

My goal is to keep the ssh connection active in background without keeping the terminal open. Any help?

1 Answer 1


You mention ssh -f, which is correct, but you missed -N, which is the remaining piece of the puzzle:

-N Do not execute a remote command. This is useful for just forwarding ports. [...]

So close! Try this

ssh -fN -L 8000:localhost:8888 myserver.com
  • Exactly what I wanted. Many thanks
    – AKMalkadi
    Feb 8 at 4:23
  • @roaima do i need to care about a timeout or is this only for sshfs? The process works infinite till i kill /suspend/reboot the background process? Jul 15 at 9:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.