From 760740905e711771144fce541da432b7b3c671ff Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Sat, 28 May 2022 03:24:48 -0700 Subject: [PATCH] ssh/tailssh: only use `login` with TTY sessions Otherwise, the shell exits immediately causing applications like mosh and VSCode to fail. Signed-off-by: Maisem Ali --- ssh/tailssh/incubator.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ssh/tailssh/incubator.go b/ssh/tailssh/incubator.go index b95e37660..ea54cbbf7 100644 --- a/ssh/tailssh/incubator.go +++ b/ssh/tailssh/incubator.go @@ -202,8 +202,10 @@ func beIncubator(args []string) error { euid := uint64(os.Geteuid()) runningAsRoot := euid == 0 - if runningAsRoot && ia.isShell && ia.loginCmdPath != "" { - // If we are trying to launch a login shell, just exec into login instead. + if runningAsRoot && ia.isShell && ia.loginCmdPath != "" && ia.hasTTY { + // If we are trying to launch a login shell, just exec into login + // instead. We can only do this if a TTY was requested, otherwise login + // exits immediately, which breaks things likes mosh and VSCode. return unix.Exec(ia.loginCmdPath, []string{ia.loginCmdPath, "-f", ia.localUser, "-h", ia.remoteIP, "-p"}, os.Environ()) }