I am running a code-server on my remote Ubuntu machine and right now my method for starting it up is to

  1. ssh -t -t user@server "code-server" on one terminal (the -t -t I got from this)
  2. ssh -N -L 8443: user@server on a second terminal
  3. Open the application on the browser

Then when I want to close it, I just close both terminals. My question is if would be possible to do this using only one connection, currently I have to authenticate twice because this requires two ssh sessions, one for starting the application and sending the KILL when closed and another one for the tunneling.

1 Answer 1


I've tested the following and it seems to work:

ssh -t -t -L 8443:localhost:8443 user@server "sleep 3"

Connection to server closed.

it waits for 3 seconds and then closes the SSH session. I'd say you can put your application in the quotes instead of sleep 3 or remove the whole "sleep 3" and that would give you interactive shell.

  • 1
    That works perfectly! I didn't realize I could just chain them together Commented Jun 9, 2022 at 7:18

You must log in to answer this question.

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