diff --git a/cmd/osssh/osssh.go b/cmd/osssh/osssh.go index b29b7ec..8c1c243 100644 --- a/cmd/osssh/osssh.go +++ b/cmd/osssh/osssh.go @@ -19,11 +19,15 @@ type Process interface { Close() error } -var remotePids []int -var hypervisor string +var ( + remotePids []int + hypervisor string + username string +) func main() { args := utils.ParseArgs() + username = args.Username setupCleanup() osc, err := openstack.CreateClient() if err != nil { @@ -46,7 +50,7 @@ func main() { } } -func run (info *openstack.Info, args generic.Args) error{ +func run (info *openstack.Info, args generic.Args) error { fmt.Print("Connecting to SSH...") c, err := ssh.NewClient(hypervisor, args.Username) if err != nil { @@ -81,7 +85,7 @@ func run (info *openstack.Info, args generic.Args) error{ } func cleanup() { - c, err := ssh.NewClient(hypervisor, "jlamp") + c, err := ssh.NewClient(hypervisor, username) if err != nil { fmt.Printf("Error creating SSH client: %s\n", err) panic(err.Error()) diff --git a/internal/ssh/ssh.go b/internal/ssh/ssh.go index 10895d6..dc2f3b5 100644 --- a/internal/ssh/ssh.go +++ b/internal/ssh/ssh.go @@ -3,6 +3,7 @@ package ssh import ( "bytes" "encoding/base64" + "fmt" "log" "net" "os" @@ -50,9 +51,12 @@ func NewClient(hostname string, username string) (*ssh.Client, error) { // Connect client, err := ssh.Dial("tcp", net.JoinHostPort(hostname, "22"), config) if err != nil { + if err.Error() == "ssh: handshake failed: knownhosts: key is unknown" { + fmt.Printf("Error\n\nCould not verify host key of %s, please add it to your known_hosts file by connecting to it with SSH\n", hostname) + os.Exit(1) + } return nil, err } - return client, nil }