Skip to content

Commit

Permalink
Adding required config param for HostKeyCallback
Browse files Browse the repository at this point in the history
  • Loading branch information
thoeni committed Jul 21, 2017
1 parent 7dfcede commit 3e8897c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions bassh.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ func (client *SSHClient) InitStandardSession() error {

//CloseSession closes the session for the client
func (client *SSHClient) CloseSession() {
client.Session.Close()
if client.Session == nil {
return
}
if err := client.Session.Close(); err != nil {
fmt.Printf("Error while closing session: %s", err)
}
}

func (client *SSHClient) prepareCommand(session *ssh.Session, params *SSHParams) error {
Expand Down Expand Up @@ -205,6 +210,7 @@ func ConfigureCredentials(username string, keypath string) (*ssh.ClientConfig, e
return nil, err
}
config.Auth = []ssh.AuthMethod{authMethod}
config.HostKeyCallback = ssh.InsecureIgnoreHostKey()
return &config, nil
}

Expand All @@ -222,7 +228,8 @@ func CreateClient(sshConfig *ssh.ClientConfig, ipAddr string, port int) *SSHClie
func (client *SSHClient) Run(command string) {

if err := client.InitStandardSession(); err != nil {
fmt.Errorf("Error while initialising SSH session! Error was: %s", err)
fmt.Printf("Error while initialising SSH session! Error was: %s\n", err)
return
}
defer client.CloseSession()

Expand Down

0 comments on commit 3e8897c

Please sign in to comment.