Skip to content

Commit

Permalink
match SSH questions
Browse files Browse the repository at this point in the history
  • Loading branch information
mikew committed Oct 21, 2024
1 parent 62e53cc commit 8fa983b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/nvrh_ssh/internal_ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func GetSshClientForServer(endpoint *SshEndpoint) (*ssh.Client, error) {
}))

authMethods = append(authMethods, ssh.PasswordCallback(func() (string, error) {
password, err := askForPassword(fmt.Sprintf("Password for %s: ", endpoint))
password, err := askForPassword(fmt.Sprintf("%s's password: ", endpoint))
if err != nil {
slog.Error("Error reading password", "err", err)
return "", err
Expand Down Expand Up @@ -89,7 +89,7 @@ func getSignerForIdentityFile(hostname string) (ssh.Signer, error) {
signer, err := ssh.ParsePrivateKey(key)
if err != nil {
if _, ok := err.(*ssh.PassphraseMissingError); ok {
passPhrase, _ := askForPassword(fmt.Sprintf("Passphrase for %s: ", identityFile))
passPhrase, _ := askForPassword(fmt.Sprintf("Enter passphrase for key '%s': ", identityFile))

signer, signerErr := ssh.ParsePrivateKeyWithPassphrase(key, passPhrase)
if signerErr != nil {
Expand Down
7 changes: 6 additions & 1 deletion src/nvrh_ssh/ssh_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ type SshEndpoint struct {
}

func (e *SshEndpoint) String() string {
return fmt.Sprintf("%s@%s:%s", e.FinalUser(), e.GivenHost, e.FinalPort())
portPart := ""
if e.FinalPort() != "22" {
portPart = fmt.Sprintf(":%s", e.FinalPort())
}

return fmt.Sprintf("%s@%s%s", e.FinalUser(), e.FinalHost(), portPart)
}

func (e *SshEndpoint) FinalUser() string {
Expand Down

0 comments on commit 8fa983b

Please sign in to comment.