Skip to content

Commit

Permalink
Merge pull request melbahja#47 from stensonb/default-user
Browse files Browse the repository at this point in the history
set default user based on current user
  • Loading branch information
melbahja committed Feb 21, 2023
2 parents 724d025 + afcffac commit 6258fe9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions examples/goph/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"log"
"net"
"os"
osuser "os/user"
"path/filepath"
"strings"
"time"

Expand Down Expand Up @@ -53,11 +55,16 @@ var (
)

func init() {
usr, err := osuser.Current()
if err != nil {
fmt.Println("couldn't determine current user. defaulting to 'root'")
usr.Username = "root"
}

flag.StringVar(&addr, "ip", "127.0.0.1", "machine ip address.")
flag.StringVar(&user, "user", "root", "ssh user.")
flag.StringVar(&user, "user", usr.Username, "ssh user.")
flag.UintVar(&port, "port", 22, "ssh port number.")
flag.StringVar(&key, "key", strings.Join([]string{os.Getenv("HOME"), ".ssh", "id_rsa"}, "/"), "private key path.")
flag.StringVar(&key, "key", filepath.Join(os.Getenv("HOME"), ".ssh", "id_rsa"), "private key path.")
flag.StringVar(&cmd, "cmd", "", "command to run.")
flag.BoolVar(&pass, "pass", false, "ask for ssh password instead of private key.")
flag.BoolVar(&agent, "agent", false, "use ssh agent for authentication (unix systems only).")
Expand Down

0 comments on commit 6258fe9

Please sign in to comment.