diff --git a/components/supervisor/pkg/supervisor/ssh.go b/components/supervisor/pkg/supervisor/ssh.go index 67aa96967df148..fe879592f07d0e 100644 --- a/components/supervisor/pkg/supervisor/ssh.go +++ b/components/supervisor/pkg/supervisor/ssh.go @@ -8,6 +8,7 @@ import ( "bufio" "context" "fmt" + "io/ioutil" "net" "os" "os/exec" @@ -85,7 +86,7 @@ func (s *sshServer) handleConn(ctx context.Context, conn net.Conn) { } args := []string{ - "-iedD", "-f/dev/null", + "-ieD", "-f/dev/null", "-oProtocol 2", "-oAllowUsers gitpod", "-oPasswordAuthentication no", @@ -213,3 +214,36 @@ func writeSSHEnv(cfg *Config, envvars []string) error { return nil } + +func configureSSHDefaultDir(cfg *Config) { + if cfg.RepoRoot == "" { + log.Error("cannot configure ssh default dir with empty repo root") + return + } + file, err := os.OpenFile("/home/gitpod/.bashrc", os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o644) + if err != nil { + log.WithError(err).Error("cannot write .bashrc") + } + defer file.Close() + if _, err := file.WriteString(fmt.Sprintf("\nif [[ -n $SSH_CONNECTION ]]; then cd \"%s\"; fi\n", cfg.RepoRoot)); err != nil { + log.WithError(err).Error("write .bashrc failed") + } +} + +func configureSSHMessageOfTheDay() { + msg := []byte(`Welcome to Gitpod: Always ready to code. Try the following commands to get started: + + gp tasks list List all your defined tasks in .gitpod.yml + gp tasks attach Attach your terminal to a workspace task + + gp ports list Lists workspace ports and their states + gp stop Stop current workspace + gp help To learn about the gp CLI commands + +For more information, see the Gitpod documentation: https://gitpod.io/docs +`) + + if err := ioutil.WriteFile("/etc/motd", msg, 0o644); err != nil { + log.WithError(err).Error("write /etc/motd failed") + } +} diff --git a/components/supervisor/pkg/supervisor/supervisor.go b/components/supervisor/pkg/supervisor/supervisor.go index 37504bc44a3f28..a7ba8b6929a0b9 100644 --- a/components/supervisor/pkg/supervisor/supervisor.go +++ b/components/supervisor/pkg/supervisor/supervisor.go @@ -1234,7 +1234,8 @@ func startSSHServer(ctx context.Context, cfg *Config, wg *sync.WaitGroup, childP log.WithError(err).Error("err creating SSH server") return } - + configureSSHDefaultDir(cfg) + configureSSHMessageOfTheDay() err = ssh.listenAndServe() if err != nil { log.WithError(err).Error("err starting SSH server")