diff options
Diffstat (limited to 'modules/ssh/ssh.go')
-rw-r--r-- | modules/ssh/ssh.go | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go index 5e3761ca19..706f5e7503 100644 --- a/modules/ssh/ssh.go +++ b/modules/ssh/ssh.go @@ -7,6 +7,7 @@ package ssh import ( + "fmt" "io" "io/ioutil" "net" @@ -82,14 +83,16 @@ func handleServerConn(keyID string, chans <-chan ssh.NewChannel) { return } - go io.Copy(ch, stdout) - go io.Copy(ch.Stderr(), stderr) - go io.Copy(input, ch) - if err = cmd.Start(); err != nil { log.Error(3, "Start: %v", err) return - } else if err = cmd.Wait(); err != nil { + } + + go io.Copy(input, ch) + io.Copy(ch, stdout) + io.Copy(ch.Stderr(), stderr) + + if err = cmd.Wait(); err != nil { log.Error(3, "Wait: %v", err) return } @@ -142,7 +145,16 @@ func Listen(port int) { }, } - privateBytes, err := ioutil.ReadFile(filepath.Join(models.SSHPath, "id_rsa")) + keyPath := filepath.Join(setting.AppDataPath, "ssh/gogs.rsa") + if !com.IsExist(keyPath) { + os.MkdirAll(filepath.Dir(keyPath), os.ModePerm) + _, stderr, err := com.ExecCmd("ssh-keygen", "-f", keyPath, "-t", "rsa", "-N", "") + if err != nil { + panic(fmt.Sprintf("Fail to generate private key: %v - %s", err, stderr)) + } + } + + privateBytes, err := ioutil.ReadFile(keyPath) if err != nil { panic("Fail to load private key") } |