diff --git a/README.md b/README.md index e160998b..fa55e264 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 @@ -81,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/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..f8737948 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: @@ -79,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`."}, 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 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.