@@ -35,6 +35,13 @@ func quoteShellArgs(args []string) string {
35
35
36
36
// SSHExec executes a command over SSH and redirects file-descriptors
37
37
func SSHExec (publicIPAddress string , privateIPAddress string , command []string , checkConnection bool , gatewayIPAddress string ) error {
38
+ gatewayUser := "root"
39
+ if strings .Contains (gatewayIPAddress , "@" ) {
40
+ parts := strings .Split (gatewayIPAddress , "@" )
41
+ gatewayUser = parts [0 ]
42
+ gatewayIPAddress = parts [1 ]
43
+ }
44
+
38
45
if publicIPAddress == "" && gatewayIPAddress == "" {
39
46
return errors .New ("server does not have public IP" )
40
47
}
@@ -52,7 +59,7 @@ func SSHExec(publicIPAddress string, privateIPAddress string, command []string,
52
59
}
53
60
}
54
61
55
- execCmd := append (NewSSHExecCmd (publicIPAddress , privateIPAddress , true , nil , command , gatewayIPAddress ))
62
+ execCmd := append (NewSSHExecCmd (publicIPAddress , privateIPAddress , true , nil , command , gatewayUser + "@" + gatewayIPAddress , "root" ))
56
63
57
64
log .Debugf ("Executing: ssh %s" , quoteShellArgs (execCmd ))
58
65
@@ -64,8 +71,15 @@ func SSHExec(publicIPAddress string, privateIPAddress string, command []string,
64
71
}
65
72
66
73
// NewSSHExecCmd computes execve compatible arguments to run a command via ssh
67
- func NewSSHExecCmd (publicIPAddress string , privateIPAddress string , allocateTTY bool , sshOptions []string , command []string , gatewayIPAddress string ) []string {
74
+ func NewSSHExecCmd (publicIPAddress string , privateIPAddress string , allocateTTY bool , sshOptions []string , command []string , gatewayIPAddress string , sshUser string ) []string {
68
75
useGateway := gatewayIPAddress != ""
76
+ gatewayUser := "root"
77
+ if useGateway && strings .Contains (gatewayIPAddress , "@" ) {
78
+ parts := strings .Split (gatewayIPAddress , "@" )
79
+ gatewayUser = parts [0 ]
80
+ gatewayIPAddress = parts [1 ]
81
+ }
82
+
69
83
execCmd := []string {}
70
84
71
85
if os .Getenv ("DEBUG" ) != "1" {
@@ -80,9 +94,9 @@ func NewSSHExecCmd(publicIPAddress string, privateIPAddress string, allocateTTY
80
94
execCmd = append (execCmd , strings .Join (sshOptions , " " ))
81
95
}
82
96
83
- execCmd = append (execCmd , "-l" , "root" )
97
+ execCmd = append (execCmd , "-l" , sshUser )
84
98
if useGateway {
85
- proxyCommand := NewSSHExecCmd (gatewayIPAddress , "" , allocateTTY , []string {"-W" , "%h:%p" }, nil , "" )
99
+ proxyCommand := NewSSHExecCmd (gatewayIPAddress , "" , allocateTTY , []string {"-W" , "%h:%p" }, nil , "" , gatewayUser )
86
100
execCmd = append (execCmd , privateIPAddress , "-o" , "ProxyCommand=ssh " + strings .Join (proxyCommand , " " ))
87
101
} else {
88
102
execCmd = append (execCmd , publicIPAddress )
0 commit comments