Skip to content

Commit

Permalink
fix: Fix default ssh shell (#411)
Browse files Browse the repository at this point in the history
Signed-off-by: Ce Gao <cegao@tensorchord.ai>
  • Loading branch information
gaocegege authored Jun 17, 2022
1 parent 5f3b16b commit 8531491
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
9 changes: 8 additions & 1 deletion cmd/envd-ssh/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
flagAuthKey = "authorized-keys"
flagNoAuth = "no-auth"
flagPort = "port"
flagShell = "shell"
)

func main() {
Expand Down Expand Up @@ -66,6 +67,11 @@ func main() {
Name: flagPort,
Usage: "port to listen on",
},
&cli.StringFlag{
Name: flagShell,
Usage: "shell to use",
Value: "bash",
},
}

// Deal with debug flag.
Expand All @@ -86,10 +92,11 @@ func main() {
}

func sshServer(c *cli.Context) error {
shell, err := sshd.GetShell()
err := sshd.GetShell(c.String(flagShell))
if err != nil {
logrus.Fatal(err.Error())
}
shell := c.String(flagShell)

port := c.Int(flagPort)
if port == 0 {
Expand Down
7 changes: 4 additions & 3 deletions pkg/docker/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (

const (
template = `set -e
/var/envd/bin/envd-ssh --authorized-keys %s --port %d &
/var/envd/bin/envd-ssh --authorized-keys %s --port %d --shell %s &
%s
wait -n`
)
Expand All @@ -34,8 +34,9 @@ func entrypointSH(g ir.Graph, workingDir string, sshPort int) string {
if g.JupyterConfig != nil {
cmds := jupyter.GenerateCommand(g, workingDir)
return fmt.Sprintf(template,
config.ContainerauthorizedKeysPath, sshPort, strings.Join(cmds, " "))
config.ContainerauthorizedKeysPath, sshPort, g.Shell,
strings.Join(cmds, " "))
}
return fmt.Sprintf(template,
config.ContainerauthorizedKeysPath, sshPort, "")
config.ContainerauthorizedKeysPath, sshPort, g.Shell, "")
}
20 changes: 6 additions & 14 deletions pkg/remote/sshd/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,15 @@ import (

var (
errNoShell = fmt.Errorf("failed to find any shell in the PATH")

shells = []string{
"zsh",
"bash",
"sh",
}
)

// GetShell returns the shell in $PATH.
func GetShell() (string, error) {
for _, shell := range shells {
if path, err := exec.LookPath(shell); err == nil {
logrus.Infof("%s exists at %s", shell, path)
return shell, nil
}
logrus.Debugf("%s does not exist", shell)
func GetShell(shell string) error {
if path, err := exec.LookPath(shell); err == nil {
logrus.Infof("%s exists at %s", shell, path)
return nil
}
logrus.Debugf("%s does not exist", shell)

return "", errNoShell
return errNoShell
}

0 comments on commit 8531491

Please sign in to comment.