mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-27 20:36:29 -04:00
Check against ~/.ssh/known_hosts
This commit is contained in:
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
// global variables used across multiple files
|
||||
var (
|
||||
home, _ = os.UserHomeDir()
|
||||
Home, _ = os.UserHomeDir()
|
||||
)
|
||||
|
||||
// global constants used across multiple files
|
||||
|
||||
@@ -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
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user