mirror of
https://github.com/coalaura/up.git
synced 2025-07-18 21:53:23 +00:00
fallback to default keys
This commit is contained in:
@ -2,10 +2,40 @@ package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
var DefaultKeyNames = []string{
|
||||
"id_ed25519",
|
||||
"id_ecdsa",
|
||||
"id_rsa",
|
||||
}
|
||||
|
||||
func FindPrivateKey() (string, error) {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, name := range DefaultKeyNames {
|
||||
path := filepath.Join(home, ".ssh", name)
|
||||
|
||||
if _, err := os.Stat(path); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
continue
|
||||
}
|
||||
|
||||
return "", err
|
||||
}
|
||||
|
||||
return path, nil
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func LoadPrivateKey(path string) (ssh.Signer, error) {
|
||||
key, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
|
@ -85,8 +85,15 @@ func run(_ context.Context, cmd *cli.Command) error {
|
||||
port = hostArg[index+1:]
|
||||
}
|
||||
|
||||
if found, _ := cfg.Get(hostname, "IdentityFile"); found != "" {
|
||||
identity = found
|
||||
if identity == "" {
|
||||
if found, _ := cfg.Get(hostname, "IdentityFile"); found != "" {
|
||||
identity = found
|
||||
} else {
|
||||
identity, err = FindPrivateKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if found, _ := cfg.Get(hostname, "HostName"); found != "" {
|
||||
|
@ -25,7 +25,7 @@ func (pr *ProgressReader) Read(p []byte) (int, error) {
|
||||
pr.read += int64(n)
|
||||
|
||||
percentage := float64(pr.read) / float64(pr.total) * 100
|
||||
log.Printf("\r%s: %.1f%%", pr.label, percentage)
|
||||
log.Printf("\r%s: %.1f%% ", pr.label, percentage)
|
||||
|
||||
return n, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user