Skip to content

Commit

Permalink
SSH print cli: more useful order for arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
simcap committed Feb 14, 2018
1 parent 23ad122 commit e605570
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (c *Client) localExec() ([]string, bool) {
exists = false
bin = "ssh"
}
args := []string{bin, fmt.Sprintf("%s@%s", c.User, c.IP)}
args := []string{bin}
if len(c.Keypath) > 0 {
args = append(args, "-i", c.Keypath)
}
Expand All @@ -227,6 +227,9 @@ func (c *Client) localExec() ([]string, bool) {
if !c.StrictHostKeyChecking {
args = append(args, "-o", "StrictHostKeychecking=no")
}

args = append(args, fmt.Sprintf("%s@%s", c.User, c.IP))

if c.Proxy != nil {
var keyArg string
if k := c.Proxy.Keypath; len(k) > 0 {
Expand Down
6 changes: 3 additions & 3 deletions ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,17 +194,17 @@ func TestCLIAndConfig(t *testing.T) {
},
{
&Client{Port: 8022, IP: "1.2.3.4", User: "ec2-user", StrictHostKeyChecking: true},
"/usr/bin/ssh ec2-user@1.2.3.4 -p 8022",
"/usr/bin/ssh -p 8022 ec2-user@1.2.3.4",
"\nHost TestHost\n Hostname 1.2.3.4\n User ec2-user\n Port 8022",
},
{
&Client{Port: 22, IP: "1.2.3.4", User: "ec2-user", StrictHostKeyChecking: true, Keypath: "/path/to/key"},
"/usr/bin/ssh ec2-user@1.2.3.4 -i /path/to/key",
"/usr/bin/ssh -i /path/to/key ec2-user@1.2.3.4",
"\nHost TestHost\n Hostname 1.2.3.4\n User ec2-user\n IdentityFile /path/to/key",
},
{
&Client{Port: 22, IP: "1.2.3.4", User: "ec2-user", StrictHostKeyChecking: false},
"/usr/bin/ssh ec2-user@1.2.3.4 -o StrictHostKeychecking=no",
"/usr/bin/ssh -o StrictHostKeychecking=no ec2-user@1.2.3.4",
"\nHost TestHost\n Hostname 1.2.3.4\n User ec2-user\n StrictHostKeychecking no",
},
}
Expand Down

0 comments on commit e605570

Please sign in to comment.