Skip to content

Commit c1590f9

Browse files
committed
Run ssh as an external command.
1 parent 8dc5800 commit c1590f9

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cli.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ func Run(cmd *cobra.Command, args []string) (err error) {
6868
return err
6969
}
7070

71-
err = ExecSshLogin(viper.GetString("username"), ConnectHost, localPort, viper.GetString("identity-file"))
71+
cmdSsh, err := execSshCommand(ctx, viper.GetString("username"), ConnectHost, localPort, viper.GetString("identity-file"))
72+
cmdSsh.Wait()
7273

7374
return err
7475
}

external-command.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
const (
1111
CmdSessionManagerPlugin string = "session-manager-plugin"
1212
CmdSessionManagerPluginOrder string = "StartSession"
13+
CmdSsh string = "ssh"
1314
)
1415

1516
func execExternalCommand(ctx context.Context, externalCommand string, args []string) (command *exec.Cmd, err error) {
@@ -32,3 +33,9 @@ func checkSessionManagerCommandIsExist() (err error) {
3233
err = exec.Command(CmdSessionManagerPlugin, "--version").Run()
3334
return err
3435
}
36+
37+
func execSshCommand(ctx context.Context, username, host, port, identityFilePath string) (command *exec.Cmd, err error) {
38+
args := []string{"-p", port, "-i", identityFilePath, username + "@" + host}
39+
command, err = execExternalCommand(ctx, CmdSsh, args)
40+
return command, err
41+
}

0 commit comments

Comments
 (0)