Skip to content

Commit

Permalink
Patch SSH key trials
Browse files Browse the repository at this point in the history
  • Loading branch information
MightyMoud committed Oct 7, 2024
1 parent 5ce79b3 commit d70beb3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 0 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ before:
builds:
- env:
- CGO_ENABLED=0
ldflags:
- "-X 'github.com/mightymoud/sidekick/cmd.version={{.Tag}}'"
goos:
- linux
- windows
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"github.com/spf13/cobra"
)

var version = "dev"
var version = "v0.6.2"

var rootCmd = &cobra.Command{
Use: "sidekick",
Expand Down
33 changes: 22 additions & 11 deletions utils/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os/user"
"path"
"strings"
"time"

"github.com/mightymoud/sidekick/render"
"github.com/skeema/knownhosts"
Expand Down Expand Up @@ -115,19 +116,29 @@ func GetSshClient(server string, sshUser string) (*ssh.Client, error) {
}
return err
})
// now that we have our key, we need to start ssh client sesssion
config := &ssh.ClientConfig{
User: sshUser,
Auth: authMethods,
HostKeyCallback: cb,
}

// create SSH client with the said config and connect to server
client, sshClientErr := ssh.Dial("tcp", fmt.Sprintf("%s:%s", server, sshPort), config)
if sshClientErr != nil {
log.Fatalf("Failed to create ssh client to the server: %v", sshClientErr)
}
var client *ssh.Client

// This error will be thrown when one method/key doesn't work
var expectedClientErr = errors.New("ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain")
for _, method := range authMethods {
config := &ssh.ClientConfig{
User: sshUser,
Auth: []ssh.AuthMethod{method},
HostKeyCallback: cb,
Timeout: 5 * time.Second,
}

workingClient, sshClientErr := ssh.Dial("tcp", fmt.Sprintf("%s:%s", server, sshPort), config)
if sshClientErr != nil {
if sshClientErr.Error() != expectedClientErr.Error() {
log.Fatalf("Failed to create ssh client to the server: %v", sshClientErr)
}
continue
}
client = workingClient
break
}
return client, nil
}

Expand Down

0 comments on commit d70beb3

Please sign in to comment.