Check against ~/.ssh/known_hosts

This commit is contained in:
2024-05-15 17:12:09 -04:00
parent 4c3b5bf7ae
commit 6f10a041de
3 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -6,7 +6,7 @@ import (
// global variables used across multiple files
var (
home, _ = os.UserHomeDir()
Home, _ = os.UserHomeDir()
)
// global constants used across multiple files
+2 -2
View File
@@ -3,8 +3,8 @@
package backend
// EntryRoot path to libmutton entry directory
var EntryRoot = home + "/.local/share/libmutton"
var ConfigDir = home + "/.config/libmutton"
var EntryRoot = Home + "/.local/share/libmutton"
var ConfigDir = Home + "/.config/libmutton"
var ConfigPath = ConfigDir + "/libmutton.ini"
// PathSeparator defines the character used to separate directories in a path (platform-specific)
+9 -1
View File
@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/rwinkhart/MUTN/src/backend"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/knownhosts"
"os"
"strconv"
"strings"
@@ -46,14 +47,21 @@ func getSSHOutput(cmd string, manualSync bool) string {
os.Exit(1)
}
// read known hosts file
hostKeyCallback, err := knownhosts.New(backend.Home + "/.ssh/known_hosts")
if err != nil {
fmt.Println(backend.AnsiError + "Sync failed - Unable to read known hosts file:" + err.Error() + backend.AnsiReset)
os.Exit(1)
}
// configure SSH client
sshConfig := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{
ssh.PublicKeys(parsedKey),
},
HostKeyCallback: hostKeyCallback,
}
sshConfig.HostKeyCallback = ssh.InsecureIgnoreHostKey() // TODO remove
// connect to SSH server
sshClient, err := ssh.Dial("tcp", ip+":"+port, sshConfig)