use C:\Windows\System32\OpenSSH\ssh.exe (#4933)

cmd/tailscale: make ssh command prefer Windows ssh.exe over PATH

Signed-off-by: Yasuhiro Matsumoto <mattn.jp@gmail.com>
pull/4946/head
mattn 2 years ago committed by GitHub
parent 9294a14a37
commit 1d04e01d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,7 +11,6 @@ import (
"fmt"
"log"
"os"
"os/exec"
"os/user"
"path/filepath"
"runtime"
@ -63,7 +62,7 @@ func runSSH(ctx context.Context, args []string) error {
hostForSSH = v
}
ssh, err := exec.LookPath("ssh")
ssh, err := findSSH()
if err != nil {
// TODO(bradfitz): use Go's crypto/ssh client instead
// of failing. But for now:

@ -10,9 +10,14 @@ package cli
import (
"errors"
"os"
"os/exec"
"syscall"
)
func findSSH() (string, error) {
return exec.LookPath("ssh")
}
func execSSH(ssh string, argv []string) error {
if err := syscall.Exec(ssh, argv, os.Environ()); err != nil {
return err

@ -8,6 +8,10 @@ import (
"errors"
)
func findSSH() (string, error) {
return "", errors.New("Not implemented")
}
func execSSH(ssh string, argv []string) error {
return errors.New("Not implemented")
}

@ -8,8 +8,21 @@ import (
"errors"
"os"
"os/exec"
"path/filepath"
)
func findSSH() (string, error) {
// use C:\Windows\System32\OpenSSH\ssh.exe since unexpected behavior
// occured with ssh.exe provided by msys2/cygwin and other environments.
if systemRoot := os.Getenv("SystemRoot"); systemRoot != "" {
exe := filepath.Join(systemRoot, "System32", "OpenSSH", "ssh.exe")
if st, err := os.Stat(exe); err == nil && !st.IsDir() {
return exe, nil
}
}
return exec.LookPath("ssh")
}
func execSSH(ssh string, argv []string) error {
// Don't use syscall.Exec on Windows, it's not fully implemented.
cmd := exec.Command(ssh, argv[1:]...)

Loading…
Cancel
Save