Skip to content

Commit

Permalink
Use hostname instead of the IP when running the actual ssh command (#…
Browse files Browse the repository at this point in the history
…4673)

This is implementing the same fix that was added for the CA mode for vault
ssh in #3922
Using the IP address caused `Host` entries in the ssh_config to not
match anymore meaning you would need to hardcode all of your IP
addresses in your ssh config instead of using DNS to connect to hosts
  • Loading branch information
Crazybus authored and jefferai committed Jun 1, 2018
1 parent 7783b23 commit b48a8e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions command/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func (c *SSHCommand) Run(args []string) int {
case ssh.KeyTypeCA:
return c.handleTypeCA(username, hostname, ip, sshArgs)
case ssh.KeyTypeOTP:
return c.handleTypeOTP(username, ip, sshArgs)
return c.handleTypeOTP(username, hostname, ip, sshArgs)
case ssh.KeyTypeDynamic:
return c.handleTypeDynamic(username, ip, sshArgs)
default:
Expand Down Expand Up @@ -482,7 +482,7 @@ func (c *SSHCommand) handleTypeCA(username, hostname, ip string, sshArgs []strin
}

// handleTypeOTP is used to handle SSH logins using the "otp" key type.
func (c *SSHCommand) handleTypeOTP(username, ip string, sshArgs []string) int {
func (c *SSHCommand) handleTypeOTP(username, hostname string, ip string, sshArgs []string) int {
secret, cred, err := c.generateCredential(username, ip)
if err != nil {
c.UI.Error(fmt.Sprintf("failed to generate credential: %s", err))
Expand Down Expand Up @@ -515,7 +515,7 @@ func (c *SSHCommand) handleTypeOTP(username, ip string, sshArgs []string) int {
"-o UserKnownHostsFile=" + c.flagUserKnownHostsFile,
"-o StrictHostKeyChecking=" + c.flagStrictHostKeyChecking,
"-p", cred.Port,
username + "@" + ip,
username + "@" + hostname,
}, sshArgs...)
cmd = exec.Command("ssh", args...)
} else {
Expand All @@ -525,7 +525,7 @@ func (c *SSHCommand) handleTypeOTP(username, ip string, sshArgs []string) int {
"-o UserKnownHostsFile=" + c.flagUserKnownHostsFile,
"-o StrictHostKeyChecking=" + c.flagStrictHostKeyChecking,
"-p", cred.Port,
username + "@" + ip,
username + "@" + hostname,
}, sshArgs...)
cmd = exec.Command(sshpassPath, args...)
env := os.Environ()
Expand Down

0 comments on commit b48a8e5

Please sign in to comment.