Code Monkey home page Code Monkey logo

lssh's Introduction

TravisCI Go Report Card

lssh

TUI list select ssh/scp/sftp client tools.

Description

This command utility to read a prepared list in advance and connect ssh/scp/sftp the selected host. List file is set in yaml format. When selecting a host, you can filter by keywords. Can execute commands concurrently to multiple hosts.

lssh also has a shell (parallel shell) that connects to multiple hosts at the same time and pipes the execution results of local commands and remote hosts. In addition, lsftp also has a shell that can be connected in parallel.

Supported multiple ssh proxy, http/socks5 proxy, x11 forward, and port forwarding.

Features

  • List selection type ssh client.
  • It can run on Linux, macOS and Windows.
  • Pure Go.
  • Commands can be executed by ssh connection in parallel.
  • There is a shell function that connects to multiple hosts in parallel for interactive operation and connects with local commands via pipes.
  • Supported multiple proxy, ssh, http, and socks5 proxy. It's supported multi-stage proxy.
  • Supported ssh-agent.
  • Supported Local and Remote Port forward, Dynamic Forward, Reverse Dynamic Forward and x11 forward.
  • Can use bashrc of local machine at ssh connection destination.
  • It supports various authentication methods. Password, Public key, Certificate and PKCS11(Yubikey etc.).
  • Can read the OpenSSH config (~/.ssh/config) and use it as it is.

Demo

run MacOSX

run Linux(Manjaro)

run Windows(Windows 10)

Install

compile

compile gofile(tested go1.17.6).

GO111MODULE=auto go get -u github.com/blacknon/lssh/cmd/lssh
GO111MODULE=auto go get -u github.com/blacknon/lssh/cmd/lscp
GO111MODULE=auto go get -u github.com/blacknon/lssh/cmd/lsftp

# copy sample config. create `~/.lssh.conf`.
test -f ~/.lssh.conf||curl -s https://raw.githubusercontent.com/blacknon/lssh/master/example/config.tml -o ~/.lssh.conf

or

git clone https://github.com/blacknon/lssh
cd lssh
GO111MODULE=auto make && sudo make install

# copy sample config. create `~/.lssh.conf`.
test -f ~/.lssh.conf||curl -s https://raw.githubusercontent.com/blacknon/lssh/master/example/config.tml -o ~/.lssh.conf

brew install

brew install(Mac OS X)

brew tap blacknon/lssh
brew install lssh

# copy sample config. create `~/.lssh.conf`.
test -f ~/.lssh.conf||curl -s https://raw.githubusercontent.com/blacknon/lssh/master/example/config.tml -o ~/.lssh.conf

Config

Please edit "~/.lssh.conf".
For details see wiki.

Usage

lssh

run command.

lssh

option(lssh)

NAME:
    lssh - TUI list select and parallel ssh client command.
USAGE:
    lssh [options] [commands...]

OPTIONS:
    --host servername, -H servername            connect servername.
    --file filepath, -F filepath                config filepath. (default: "/Users/uesugi/.lssh.conf")
    -L [bind_address:]port:remote_address:port  Local port forward mode.Specify a [bind_address:]port:remote_address:port. Only single connection works.
    -R [bind_address:]port:remote_address:port  Remote port forward mode.Specify a [bind_address:]port:remote_address:port.  Only single connection works.
    -D port                                     Dynamic port forward mode(Socks5). Specify a port. Only single connection works.
    -w                                          Displays the server header when in command execution mode.
    -W                                          Not displays the server header when in command execution mode.
    --not-execute, -N                           not execute remote command and shell.
    --x11, -X                                   x11 forwarding(forward to ${DISPLAY}).
    --term, -t                                  run specified command at terminal.
    --parallel, -p                              run command parallel node(tail -F etc...).
    --localrc                                   use local bashrc shell.
    --not-localrc                               not use local bashrc shell.
    --pshell, -s                                use parallel-shell(pshell) (alpha).
    --list, -l                                  print server list from config.
    --help, -h                                  print this help
    --version, -v                               print the version

COPYRIGHT:
    blacknon([email protected])

VERSION:
    0.6.7

USAGE:
    # connect ssh
    lssh

    # run command selected server over ssh.
    lssh command...

    # run command parallel in selected server over ssh.
    lssh -p command...

    # run command parallel in selected server over ssh, do it in interactively shell.
    lssh -s

lscp

run command.

lscp from... to

option(lscp)

NAME:
    lscp - TUI list select and parallel scp client command.
USAGE:
    lscp [options] (local|remote):from_path... (local|remote):to_path

OPTIONS:
    --host value, -H value  connect servernames
    --list, -l              print server list from config
    --file value, -F value  config file path (default: "/Users/uesugi/.lssh.conf")
    --permission, -p        copy file permission
    --help, -h              print this help
    --version, -v           print the version

COPYRIGHT:
    blacknon([email protected])

VERSION:
    0.6.7

USAGE:
    # local to remote scp
    lscp /path/to/local... remote:/path/to/remote

    # remote to local scp
    lscp remote:/path/to/remote... /path/to/local

    # remote to remote scp
    lscp remote:/path/to/remote... remote:/path/to/local

lsftp

run command.

lsftp

option(lsftp)

NAME:
    lsftp - TUI list select and parallel sftp client command.
USAGE:
    lsftp [options]

OPTIONS:
    --file value, -F value  config file path (default: "/Users/uesugi/.lssh.conf")
    --help, -h              print this help
    --version, -v           print the version

COPYRIGHT:
    blacknon([email protected])

VERSION:
    0.6.7

USAGE:
  # start lsftp shell
  lsftp

If you specify a command as an argument, you can select multiple hosts. Select host Tab, select all displayed hosts Ctrl + a.

1. [lssh] connect terminal

You can connect to the terminal like a normal ssh command (OpenSSH).

You can connect using a local bashrc file (if ssh login shell is bash).

~/.lssh.conf example.

[server.localrc]
addr = "192.168.100.104"
key  = "/path/to/private_key"
note = "Use local bashrc files."
local_rc = 'yes'
local_rc_compress = true # gzip compress localrc file data
local_rc_file = [
     "~/dotfiles/.bashrc"
    ,"~/dotfiles/bash_prompt"
    ,"~/dotfiles/sh_alias"
    ,"~/dotfiles/sh_export"
    ,"~/dotfiles/sh_function"
]

You can execute commands before and after ssh connection.
You can also change the color of each host's terminal by combining it with the OSC escape sequence.

if iTerm2, you can also change the profile.

~/.lssh.conf example.

[server.iTerm2_sample]
addr = "192.168.100.103"
key  = "/path/to/private_key"
note = "Before/After run local command"
pre_cmd = 'printf "\033]50;SetProfile=Theme\a"'    # ssh theme
post_cmd = 'printf "\033]50;SetProfile=Default\a"' # local theme
note = "(option) exec command after ssh disconnected."

[server.GnomeTerminal_sample]
addr = "192.168.100.103"
key  = "/path/to/private_key"
note = "Before/After run local command"
pre_cmd = 'printf "\e]10;#ffffff\a\e]11;#503000\a"'  # ssh color
post_cmd = 'printf "\e]10;#ffffff\a\e]11;#000000\a"' # local color
note = "(option) exec command after ssh disconnected."

A terminal log can be recorded by writing a configuration file.

~/.lssh.conf example.

[log]
enable = true
timestamp = true
dirpath = "~/log/lssh/<Date>/<Hostname>"

There are other parameters corresponding to ClientAliveInterval and ClientAliveCountMax.

[server.alivecount]
addr = "192.168.100.101"
key  = "/path/to/private_key"
note = "alive count max."
alive_max = 3 # ServerAliveCountMax
alive_interval = 60 # ServerAliveCountInterval

2. [lssh] run command (parallel)

It is possible to execute by specifying command in argument.
Parallel execution can be performed by adding the -p option.

# exec command over ssh.
lssh <command...>

# exec command over ssh, parallel.
lssh -p <command>

In parallel connection mode (-p option), Stdin can be sent to each host.\

Can be piped to send Stdin.

# You can pass values ​​in a pipe
command... | lssh <command...>

3. [lssh] Execute commands interactively (parallel shell)

You can send commands to multiple servers interactively.

# parallel shell connect
lssh -s

You can also combine remote and local commands.

remote_command | !local_command

4. [lscp] scp (local=>remote(multi), remote(multi)=>local, remote=>remote(multi))

You can do scp by selecting a list with the command lscp.
You can select multiple connection destinations. This program use sftp protocol.

local => remote(multiple)

# lscp local => remote(multiple)
lscp /path/to/local... r:/path/to/remote

remote(multiple) => local

# lscp remote(multiple) => local
lscp r:/path/to/remote... /path/to/local

remote => remote(multiple)

# lscp remote => remote(multiple)
lscp r:/path/to/remote... r:/path/to/local

5. [lsftp] sftp (local=>remote(multi), remote(multi)=>local)

You can do sftp by selecting a list with the command lstp.
You can select multiple connection destinations.

lsftp

6. include ~/.ssh/config file.

Load and use ~/.ssh/config by default.
ProxyCommand can also be used.

Alternatively, you can specify and read the path as follows: In addition to the path, ServerConfig items can be specified and applied collectively.

[sshconfig.default]
path = "~/.ssh/config"
pre_cmd = 'printf "\033]50;SetProfile=local\a"'
post_cmd = 'printf "\033]50;SetProfile=Default\a"'

7. include other ServerConfig file.

You can include server settings in another file.
common settings can be specified for each file that you went out.

~/.lssh.conf example.

[includes]
path = [
	 "~/.lssh.d/home.conf"
	,"~/.lssh.d/cloud.conf"
]

~/.lssh.d/home.conf example.

[common]
pre_cmd = 'printf "\033]50;SetProfile=dq\a"'       # iterm2 ssh theme
post_cmd = 'printf "\033]50;SetProfile=Default\a"' # iterm2 local theme
ssh_agent_key = ["~/.ssh/id_rsa"]
ssh_agent = false
user = "user"
key = "~/.ssh/id_rsa"
pkcs11provider = "/usr/local/lib/opensc-pkcs11.so"

[server.Server1]
addr = "172.16.200.1"
note = "TEST Server1"
local_rc = "yes"

[server.Server2]
addr = "172.16.200.2"
note = "TEST Server2"
local_rc = "yes"

The priority of setting values ​​is as follows.

[server.hogehoge] > [common] at Include file > [common] at ~/.lssh.conf

8. Supported Proxy

Supports multiple proxy.

  • http
  • socks5
  • ssh

Besides this, you can also specify ProxyCommand like OpenSSH.

http proxy example.

[proxy.HttpProxy]
addr = "example.com"
port = "8080"

[server.overHttpProxy]
addr = "over-http-proxy.com"
key  = "/path/to/private_key"
note = "connect use http proxy"
proxy = "HttpProxy"
proxy_type = "http"

socks5 proxy example.

[proxy.Socks5Proxy]
addr = "example.com"
port = "54321"

[server.overSocks5Proxy]
addr = "192.168.10.101"
key  = "/path/to/private_key"
note = "connect use socks5 proxy"
proxy = "Socks5Proxy"
proxy_type = "socks5"

ssh proxy example.

[server.sshProxyServer]
addr = "192.168.100.200"
key  = "/path/to/private_key"
note = "proxy server"

[server.overProxyServer]
addr = "192.168.10.10"
key  = "/path/to/private_key"
note = "connect use ssh proxy"
proxy = "sshProxyServer"

[server.overProxyServer2]
addr = "192.168.10.100"
key  = "/path/to/private_key"
note = "connect use ssh proxy(multiple)"
proxy = "overProxyServer"

ProxyCommand proxy example.

[server.ProxyCommand]
addr = "192.168.10.20"
key  = "/path/to/private_key"
note = "connect use ssh proxy(multiple)"
proxy_cmd = "ssh -W %h:%p proxy"

9. Available authentication method

  • Password auth
  • Publickey auth
  • Certificate auth
  • PKCS11 auth
  • Ssh-Agent auth

password auth example.

[server.PasswordAuth]
addr = "password_auth.local"
user = "user"
pass = "Password"
note = "password auth server"

publickey auth example.

[server.PublicKeyAuth]
addr = "pubkey_auth.local"
user = "user"
key = "~/path/to/key"
note = "Public key auth server"

[server.PublicKeyAuth_with_passwd]
addr = "password_auth.local"
user = "user"
key = "~/path/to/key"
keypass = "passphrase"
note = "Public key auth server with passphrase"

cert auth example.
(pkcs11 key is not supported in the current version.)

[server.CertAuth]
addr = "cert_auth.local"
user = "user"
cert = "~/path/to/cert"
certkey = "~/path/to/certkey"
note = "Certificate auth server"

[server.CertAuth_with_passwd]
addr = "cert_auth.local"
user = "user"
cert = "~/path/to/cert"
certkey = "~/path/to/certkey"
certkeypass = "passphrase"
note = "Certificate auth server with passphrase"

pkcs11 auth example.

[server.PKCS11Auth]
addr = "pkcs11_auth.local"
user = "user"
pkcs11provider = "/usr/local/lib/opensc-pkcs11.so"
pkcs11 = true
note = "PKCS11 auth server"

[server.PKCS11Auth_with_PIN]
addr = "pkcs11_auth.local"
user = "user"
pkcs11provider = "/usr/local/lib/opensc-pkcs11.so"
pkcs11 = true
pkcs11pin = "123456"
note = "PKCS11 auth server"

ssh-agent auth example.

[server.SshAgentAuth]
addr = "agent_auth.local"
user = "user"
agentauth = true # auth ssh-agent
note = "ssh-agent auth server"

10. Port forwarding

Supported Local/Remote/Dynamic port forwarding.
You can specify from the command line or from the configuration file.

command line option

lssh -L 8080:localhost:80 # local port forwarding
lssh -R 80:localhost:8080 # remote port forwarding
lssh -D 10080             # dynamic port forwarding
lssh -R 10080             # Reverse Dynamic port forwarding

config file

[server.LocalPortForward]
addr = "localforward.local"
user = "user"
agentauth = true
port_forward_local = "localhost:8080"
port_forward_remote = "localhost:80"
note = "local port forwawrd example"

[server.RemotePortForward]
addr = "remoteforward.local"
user = "user"
agentauth = true
port_forward = "REMOTE"
port_forward_local = "localhost:80"
port_forward_remote = "localhost:8080"
note = "remote port forwawrd example"

[server.DynamicForward]
addr = "dynamicforward.local"
user = "user"
agentauth = true
dynamic_port_forward = "11080"
note = "dynamic forwawrd example"

[server.ReverseDynamicForward]
addr = "reversedynamicforward.local"
user = "user"
agentauth = true
reverse_dynamic_port_forward = "11080"
note = "reverse dynamic forwawrd example"

If OpenSsh config is loaded, it will be loaded as it is.

Licence

A short snippet describing the license MIT.

Author

blacknon

lssh's People

Contributors

blacknon avatar jiro4989 avatar naofumiuesugi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

lssh's Issues

ターミナル接続時のhistoryファイルのローカル⇔リモート間での同期

ターミナル接続時に、historyファイルに追記されたコマンドをリモート⇔ローカルでの同期処理を行うことで、ローカルや同時接続しているリモートで実行したコマンドをそのままリモートに持っていったりできるようにする。

接続中の同期については、Connectを使いまわして定期的にSessionを払い出して同期処理をしてやれば問題ないと思われる。接続時の同期方法についてはまだ未検討。

Add option

Add Command Option.
ex)

  • -f PATH => config file specification.
  • -c "COMMAND" => exec only "COMMAND".
  • -p -F FROM_PATH -T TO_PATH => scp mode.
  • -m => multi line select mode(with -p)

証明書認証/PKCS#11に対応させる

Yubikeyでの環境などにも対応させたいので、証明書認証についても対応させる。
設定項目としては"cert"という項目で対応させる方向で検討中。

ServerConfにkey_cmd項目の追加

鍵ファイルを指定したコマンドから生成、読み取りできるようにする。

私用例) splitなどで鍵ファイルを分散しておき、それを復号化するコマンドを入れる、lastpass-cliなどから複合する etc...

add telnet support

Considering access to the network switch, we also support telnet connection.

/ssh配下の機能を外部のライブラリとして外出し

/sshが肥大化してきたので、以下の機能について外部ライブラリとして外出しする

  • 認証系(AuthMap周辺全部?鍵やパスワードについてはいらなそうだけど、一緒くたに移してしまう)
    • 鍵認証
    • パスワード認証
    • 証明書認証
    • PKCS11認証
    • ssh-agent認証
  • プロキシ系
    • http/httpsプロキシ
    • socks5プロキシ
    • ssh多段プロキシ
  • フォワード系
    • PortForward
    • X11Forward
  • シェルへの接続周り(local bashrcについては組み込まない)

鍵ファイルのPassphase及びPKCS11のPINの入力受付及び保持

  • 鍵ファイルにPassphaseがかかっており、かつconfigに登録されていない場合、入力を促すプロンプトを表示する(PKCS11も同様(実装済))
  • パラレル接続のため、対象の接続時は受け付けたPassphaseやPINはメモリに保持させておく

PortForward機能の追加

ssh接続時に、設定された内容でPortForwardを行うように定義する
なお、このときある程度幅をもたせた指定ができるよう考慮する(複数接続する可能性があるため)

Thanks!

This tool is awesome! Thank you very much,guys!
pls close!

list画面のインクリメンタルサーチ機能の強化

現状は平文での検索のみ行える状態だが、以下の機能を追加し検索機能を強化する
・Ctrl+Rによる検索方法の切り替え(平文⇔正規表現⇔カテゴリ)
・正規表現での検索機能の追加
・カテゴリ(サーバ名やホスト名など)別での検索機能の追加

brew installでエラー

$ brew install lsshを実行すると、404 Not Foundになってしまいます。

curl: (22) The requested URL returned error: 404 Not Found
Error: An exception occurred within a child process:
  DownloadError: Failed to download resource "lssh"
Download failed: https://github.com/blacknon/lssh/releases/download/v0.5.4/lssh_0.5.5_darwin_amd64.tar.gz

https://github.com/blacknon/homebrew-lssh/blob/master/lssh.rb
こちらで指定されているURLのバージョンがv0.5.4になっています。
おそらく↓のURLが正しいかと思います。
https://github.com/blacknon/lssh/releases/download/v0.5.5/lssh_0.5.5_darwin_amd64.tar.gz

ご確認のほどよろしくお願いいたします。

バックグラウンドでコネクションを維持して、実行コマンドを都度渡すタイプのクライアントコマンドの作成

sコマンド

  • 事前に接続処理だけ実行し、ConnectionをKeepするデーモンを立ち上げさせる
  • デーモンに対して、Socket通信で実行コマンドを都度与えることで、Sessionを立ち上げてコマンドを実行する

といったクライアントコマンドを作成。
メリットとしては、ローカルのコンソールでのリモートサーバのコマンド実行結果を扱いやすくなる。

【イメージ】

$ echo ABCD | s sed 's/$/_123/g'
SERVER1: ABCD_123
SERVER2: ABCD_123
SERVER3: ABCD_123
...

$ echo ABCD | s sed '"s/$/"$(hostname)"/g"' | sed 's/$/_'$(hostname)'/'
SERVER1: ABCD_SERVER1_localhost
SERVER2: ABCD_SERVER2_localhost
SERVER3: ABCD_SERVER3_localhost
...

ログ機能の追加

ターミナルのログ取得機能の追加。
イメージとしてはTeratermのログ。

AWS/Azure等のクラウド上のVMへの接続情報自動生成機能の追加

オプション等を付与して実行することで、confで定義されたAWS/Azure等のクラウドのAPIからVMの情報を取得し、それを元にssh接続先を生成して接続させるようにする。
都度APIにアクセスするのは非効率的のため、オプション指定がない場合は作成済みの接続情報をそのまま参照することとする。

includeのリストでの指定

現在のバージョン(0.5.1)だとincludeが項目を1個1個作ってのincludeになっているため、listで一気に指定できるよう.lssh.confの読み込み内容について書き換える

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.