From fcbe196c9beb60af5a375b3df8ce1bf367981591 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 14 Sep 2020 12:25:03 +0200 Subject: [PATCH 1/4] use ~/.config/lssh/lssh.conf as default config if exists - many distros adhere XDG Base Directory Specification - see: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html - if this file does not exist, then ~/.lssh.conf is considered default config --- README.md | 6 ++++-- cmd/lscp/args.go | 3 +++ cmd/lsftp/args.go | 3 +++ cmd/lssh/args.go | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e160998b..5986970b 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,10 @@ brew install(Mac OS X) ## Config -Please edit "~/.lssh.conf".\ -For details see [wiki](https://github.com/blacknon/lssh/wiki/Config). +Default configuration file is either "~/.lssh.conf" or "~/.config/lssh/lssh.conf", +the later being used if both exists. + +For details about configuration file content see [wiki](https://github.com/blacknon/lssh/wiki/Config). ## Usage diff --git a/cmd/lscp/args.go b/cmd/lscp/args.go index 3551bc7f..3c57bfa4 100644 --- a/cmd/lscp/args.go +++ b/cmd/lscp/args.go @@ -23,6 +23,9 @@ func Lscp() (app *cli.App) { // Default config file path usr, _ := user.Current() defConf := usr.HomeDir + "/.lssh.conf" + if _, err := os.Stat(usr.HomeDir + "/.config/lssh/lssh.conf"); err == nil { + defConf = usr.HomeDir + "/.config/lssh/lssh.conf" + } // Set help templete cli.AppHelpTemplate = `NAME: diff --git a/cmd/lsftp/args.go b/cmd/lsftp/args.go index 5b17a364..3a4ae2ce 100644 --- a/cmd/lsftp/args.go +++ b/cmd/lsftp/args.go @@ -20,6 +20,9 @@ func Lsftp() (app *cli.App) { // Default config file path usr, _ := user.Current() defConf := usr.HomeDir + "/.lssh.conf" + if _, err := os.Stat(usr.HomeDir + "/.config/lssh/lssh.conf"); err == nil { + defConf = usr.HomeDir + "/.config/lssh/lssh.conf" + } // Set help templete cli.AppHelpTemplate = `NAME: diff --git a/cmd/lssh/args.go b/cmd/lssh/args.go index ea4d00b4..0c840c84 100644 --- a/cmd/lssh/args.go +++ b/cmd/lssh/args.go @@ -22,6 +22,9 @@ func Lssh() (app *cli.App) { // Default config file path usr, _ := user.Current() defConf := usr.HomeDir + "/.lssh.conf" + if _, err := os.Stat(usr.HomeDir + "/.config/lssh/lssh.conf"); err == nil { + defConf = usr.HomeDir + "/.config/lssh/lssh.conf" + } // Set help templete cli.AppHelpTemplate = `NAME: From ef189bc96db484c4f0d1a891ed88d2478360d561 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 14 Sep 2020 12:29:45 +0200 Subject: [PATCH 2/4] allow -f to be used for lssh to specify config file path - be more coherent with lscp and lsftp - -F kept for backward compatibility --- README.md | 2 +- cmd/lssh/args.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5986970b..fa55e264 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ option(lssh) OPTIONS: --host servername, -H servername connect servername. - --file filepath, -F filepath config filepath. (default: "/Users/blacknon/.lssh.conf") + --file filepath, -F filepath, -f filepath config filepath. (default: "/Users/blacknon/.lssh.conf") -L [bind_address:]port:remote_address:port Local port forward mode.Specify a [bind_address:]port:remote_address:port. -R [bind_address:]port:remote_address:port Remote port forward mode.Specify a [bind_address:]port:remote_address:port. -D port Dynamic port forward mode(Socks5). Specify a port. diff --git a/cmd/lssh/args.go b/cmd/lssh/args.go index 0c840c84..f8737948 100644 --- a/cmd/lssh/args.go +++ b/cmd/lssh/args.go @@ -82,7 +82,7 @@ USAGE: app.Flags = []cli.Flag{ // common option cli.StringSliceFlag{Name: "host,H", Usage: "connect `servername`."}, - cli.StringFlag{Name: "file,F", Value: defConf, Usage: "config `filepath`."}, + cli.StringFlag{Name: "file,F,f", Value: defConf, Usage: "config `filepath`."}, // port forward option cli.StringFlag{Name: "L", Usage: "Local port forward mode.Specify a `[bind_address:]port:remote_address:port`."}, From 4e6cbf1bb1bed525ef5627a7e83f78ab791fb892 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 18 Sep 2020 17:09:25 +0200 Subject: [PATCH 3/4] ssh - if config pass field is set to ask, prompt user to type passoword - simple variant to allow users to introduce the password per server profile - e.g: pass = "ask" --- ssh/auth.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ssh/auth.go b/ssh/auth.go index e4b7815c..0757e0d9 100644 --- a/ssh/auth.go +++ b/ssh/auth.go @@ -13,6 +13,7 @@ import ( "github.com/blacknon/go-sshlib" "github.com/blacknon/lssh/common" "golang.org/x/crypto/ssh" + "golang.org/x/crypto/ssh/terminal" ) const SSH_AUTH_SOCK = "SSH_AUTH_SOCK" @@ -42,7 +43,14 @@ func (r *Run) CreateAuthMethodMap() { // Password if config.Pass != "" { - r.registAuthMapPassword(server, config.Pass) + if config.Pass == "ask" { + fmt.Print("Enter password: ") + stdinPass, _ := terminal.ReadPassword(int(os.Stdin.Fd())); + fmt.Printf("\n") + r.registAuthMapPassword(server, strings.TrimSpace(string(stdinPass))) + } else { + r.registAuthMapPassword(server, config.Pass) + } } // Multiple Password From 1f8e26da6664fd686c4a5c79a6760408ea73ca46 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Fri, 7 Jan 2022 09:28:22 +0100 Subject: [PATCH 4/4] ssh: align printed messages --- ssh/run.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ssh/run.go b/ssh/run.go index f3141c7b..05bef54b 100644 --- a/ssh/run.go +++ b/ssh/run.go @@ -170,14 +170,14 @@ func (r *Run) Start() { // use ssh login header. func (r *Run) PrintSelectServer() { serverListStr := strings.Join(r.ServerList, ",") - fmt.Fprintf(os.Stderr, "Select Server :%s\n", serverListStr) + fmt.Fprintf(os.Stderr, "Select Server : %s\n", serverListStr) } // printRunCommand is printout run command. // use ssh command run header. func (r *Run) printRunCommand() { runCmdStr := strings.Join(r.ExecCmd, " ") - fmt.Fprintf(os.Stderr, "Run Command :%s\n", runCmdStr) + fmt.Fprintf(os.Stderr, "Run Command : %s\n", runCmdStr) } // printPortForward is printout port forwarding. @@ -194,8 +194,8 @@ func (r *Run) printPortForward(m, forwardLocal, forwardRemote string) { arrow = "<= " } - fmt.Fprintf(os.Stderr, "Port Forward :%s\n", mode) - fmt.Fprintf(os.Stderr, " local[%s] %s remote[%s]\n", forwardLocal, arrow, forwardRemote) + fmt.Fprintf(os.Stderr, "Port Forward : %s\n", mode) + fmt.Fprintf(os.Stderr, " local[%s] %s remote[%s]\n", forwardLocal, arrow, forwardRemote) } } @@ -203,8 +203,8 @@ func (r *Run) printPortForward(m, forwardLocal, forwardRemote string) { // use ssh command run header. only use shell(). func (r *Run) printDynamicPortForward(port string) { if port != "" { - fmt.Fprintf(os.Stderr, "DynamicForward:%s\n", port) - fmt.Fprintf(os.Stderr, " %s\n", "connect Socks5.") + fmt.Fprintf(os.Stderr, "DynamicForward : %s\n", port) + fmt.Fprintf(os.Stderr, " %s\n", "connect Socks5.") } } @@ -251,7 +251,7 @@ func (r *Run) printProxy(server string) { // print header header := strings.Join(array, " => ") - fmt.Fprintf(os.Stderr, "Proxy :%s\n", header) + fmt.Fprintf(os.Stderr, "Proxy : %s\n", header) } // runCmdLocal exec command local machine.