mirror of
https://github.com/psviderski/uncloud.git
synced 2026-08-28 03:53:33 +00:00
chore: set default ssh key path to ~/.ssh/id_ed25519 and handle home expansion
This commit is contained in:
@@ -62,8 +62,8 @@ func NewAddCommand() *cobra.Command {
|
|||||||
"blank '' or 'none' to disable ingress on this machine, or specify an IP address.",
|
"blank '' or 'none' to disable ingress on this machine, or specify an IP address.",
|
||||||
)
|
)
|
||||||
cmd.Flags().StringVarP(
|
cmd.Flags().StringVarP(
|
||||||
&opts.sshKey, "ssh-key", "i", "",
|
&opts.sshKey, "ssh-key", "i", "~/.ssh/id_ed25519",
|
||||||
"path to SSH private key for SSH remote login. (default ~/.ssh/id_*)",
|
"Path to SSH private key for remote login (if not already added to SSH agent).",
|
||||||
)
|
)
|
||||||
cmd.Flags().StringVar(
|
cmd.Flags().StringVar(
|
||||||
&opts.version, "version", "latest",
|
&opts.version, "version", "latest",
|
||||||
|
|||||||
@@ -80,8 +80,8 @@ func NewInitCommand() *cobra.Command {
|
|||||||
"blank '' or 'none' to disable ingress on this machine, or specify an IP address.",
|
"blank '' or 'none' to disable ingress on this machine, or specify an IP address.",
|
||||||
)
|
)
|
||||||
cmd.Flags().StringVarP(
|
cmd.Flags().StringVarP(
|
||||||
&opts.sshKey, "ssh-key", "i", "",
|
&opts.sshKey, "ssh-key", "i", "~/.ssh/id_ed25519",
|
||||||
"Path to SSH private key for SSH remote login. (default ~/.ssh/id_*)",
|
"Path to SSH private key for remote login (if not already added to SSH agent).",
|
||||||
)
|
)
|
||||||
cmd.Flags().StringVar(
|
cmd.Flags().StringVar(
|
||||||
&opts.version, "version", "latest",
|
&opts.version, "version", "latest",
|
||||||
@@ -114,7 +114,6 @@ func initCluster(ctx context.Context, uncli *cli.CLI, remoteMachine *cli.RemoteM
|
|||||||
}
|
}
|
||||||
publicIP = &ip
|
publicIP = &ip
|
||||||
}
|
}
|
||||||
|
|
||||||
client, err := uncli.InitCluster(ctx, cli.InitClusterOptions{
|
client, err := uncli.InitCluster(ctx, cli.InitClusterOptions{
|
||||||
Context: opts.context,
|
Context: opts.context,
|
||||||
MachineName: opts.name,
|
MachineName: opts.name,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/psviderski/uncloud/internal/fs"
|
||||||
"golang.org/x/crypto/ssh"
|
"golang.org/x/crypto/ssh"
|
||||||
"golang.org/x/crypto/ssh/agent"
|
"golang.org/x/crypto/ssh/agent"
|
||||||
)
|
)
|
||||||
@@ -63,6 +64,7 @@ func sshAgentAuth() (ssh.AuthMethod, func(), error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func privateKeyAuth(path string) (ssh.AuthMethod, error) {
|
func privateKeyAuth(path string) (ssh.AuthMethod, error) {
|
||||||
|
path = fs.ExpandHomeDir(path)
|
||||||
key, err := os.ReadFile(path)
|
key, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("read private key file %q: %w", path, err)
|
return nil, fmt.Errorf("read private key file %q: %w", path, err)
|
||||||
|
|||||||
Reference in New Issue
Block a user