Giter VIP home page Giter VIP logo

portainerssh's Introduction

Portainer SSH

Go Report Card Go Reference Release

Native shell client for Portainer containers, provided a powerful native terminal to manage your Docker containers.

  • It's dead simple. like the ssh cli, you do portainerssh container_name to SSH into any containers
  • It's flexible. portainerssh reads configurations from ENV, from yml or json file
  • It's powerful. portainerssh searches the whole Portainer deployment, open shell into any containers from your workstation, regardless which host it belongs to
  • It's smart. portainerssh uses fuzzy container name matching. Forget the container name? it doesn't matter, use "*" or "%" instead

Is it really an SSH client?

No. It's called so for historical purposes. It acts like SSH in terms of providing you shell access to your containers. Also SSH is what people are likely googling for.

Installation

Via Golang

go get github.com/devbranch-vadym/portainerssh

Binary builds

Binary builds may be found at releases page. We currently provide amd64 and arm64 builds for GNU/Linux and Mac and amd64 for Windows.

Configuration

The configuration could be provided by either config.json or config.yml in ./, /etc/portainerssh/ or ~/.portainerssh/ folders.

If you want to use JSON format, create a config.json in the folders with content:

{
  "api_url": "https://portainerssh.server/api",
  "user": "your_access_key",
  "password": "your_access_password",
  "endpoint": "10",
  "api_key": "your_api_key"
}

If you want to use YAML format, create a config.yml with content:

api_url: https://your.portainer.server/api
user: your_access_key
password: your_access_password
endpoint: 10 # Optional Portainer endpoint ID, defaults to 1.
api_key: your_api_key # Optional Portainer API key, defaults to empty. Replaces username and password.

We accept environment variables as well:

PORTAINER_API_URL=https://your.portainer.server/api
PORTAINER_USER=your_access_key
PORTAINER_PASSWORD=your_access_password
PORTAINER_API_KEY=your_access_token

Usage

portainerssh [<flags>] <container>

? in container name matches any single character. "%" matches zero or more characters.

Examples

portainerssh my-container-name
portainerssh my-container-%
portainerssh %-container-%
portainerssh my-container-????
portainerssh -c /bin/sh my-container-name

Flags

  -h, --help            Show context-sensitive help (also try --help-long and --help-man).
      --version         Show application version.
      --api_url=""      Portainer server API URL, https://your.portainer.server/api .
      --endpoint=1      Portainer endpoint ID. Default is 1.
      --user=""         Portainer API user/accesskey.
      --password=""     Portainer API password/secret.
      --api_key=""      Portainer API key.
  -c, --command="bash"  Command to execute inside container.
  -u, --run_as_user=""  User to execute container command as.
  -w, --workdir=""      Working directory to execute command in.

Arguments

<container>  Container name, wildcards allowed

Limitations

Currently, only Docker endpoints are supported.

History

portainerssh is based on wonderful rancherssh utility by Fang Li. In fact, portainerssh is a fork and partial rewrite of rancherssh, just for Portainer.

portainerssh's People

Contributors

dependabot[bot] avatar devbranch-vadym avatar fangli avatar korndevbr avatar robbie1977 avatar

Stargazers

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

Watchers

 avatar

portainerssh's Issues

Executing commands in a container via portainerssh

If run portainerssh <container> -c "ls" the command return the result, but if run portainerssh <container> -c "ls -l" return an error...
OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "ls -l": executable file not found in $PATH: unknown
If remove the quotes, only ls will executed and ignored -l

Need to change Command type to []string, just like Docker does
in type ContainerExecParams struct api.go

portainerssh can't configure to use in special directory.

Describe the bug
You can't configure portainerssh to use commands in special directories except a directory of container.

To Reproduce
Steps to reproduce the behavior:

  1. Began to write the command "portainerssh ..."
  2. Try to specify special directory for portainerssh
  3. ....
  4. You can't.

Expected behavior
I want to have opportunity to specify directories in portainerssh.

Actual behavior
I don't have opportunity to specify directories in portainerssh.

Environment:

  • Portainer version 2.11.0
  • portainerssh version 1.6.0

Zero (NUL) characters are printed to TTY

Describe the bug
During the shell session, zero (NUL, e.g. \0) characters may be printed to terminal.
They're not normally visible but could cause problems e.g. in CI scripts.

To Reproduce
Steps to reproduce the behavior:

  1. Run portainerssh container_name | hexdump
  2. Press any key a few times.

Expected behavior
No zero characters are printed.

Actual behavior
Pressing space leads to the following hexdump output:

00020a0 0000 0000 0000 0000 0000 0000 0000 0000

Environment:

  • Portainer version: 2.16.0
  • portainerssh 1.6.1

API token auth support is missing

Describe the bug
The API token auth is missing. This is especially an issue with newer versions of Portainer which doesn't support authenticating in API with username/password.

To Reproduce
Steps to reproduce the behavior:

  1. Install latest Portainer version.
  2. Try to run portainerssh with it.

Expected behavior
Able to log in and run the shell.

Actual behavior
Not able to log in.

Environment:

  • Portainer version: 1.6.1
  • portainerssh version: 1.6.1

Error when using Portainerssh in the pipeline

When I want to use Portainerssh in the repository pipeline container, I get the error

Connecting to a shell ...
panic: inappropriate ioctl for device
goroutine 1 [running]:
github.com/devbranch-vadym/portainerssh/pkg/wsterm.(*WebTerm).setRawtty(0xc00022d3e0, 0x0)
	/home/runner/work/portainerssh/portainerssh/pkg/wsterm/wsterm.go:64 +0xf2
github.com/devbranch-vadym/portainerssh/pkg/wsterm.(*WebTerm).Run(0xc00022d3e0)
	/home/runner/work/portainerssh/portainerssh/pkg/wsterm/wsterm.go:75 +0x58
main.main()
	/home/runner/work/portainerssh/portainerssh/main.go:26 +0x16b

The container cannot start tty inside.
https://github.com/devbranch-vadym/portainerssh/blob/master/pkg/wsterm/wsterm.go#L60

If you can fix this problem, please do it.

Return error code in portainerssh -c "..."

Describe the bug
If run portainerssh with the flag -c or --command always return 0

To Reproduce
Steps to reproduce the behavior:

  1. portainerssh YOUR_CONTAINER -c "cat file_not_exist"
  2. echo $?

Expected behavior
Return the error code of the command that is executed in the container.

Actual behavior
Returns the error code of the portainerssh

Environment:

  • Portainer version 2.11.0
  • portainerssh version 1.5.0

portainerssh: command not found

go get github.com/devbranch-vadym/portainerssh

go: downloading github.com/devbranch-vadym/portainerssh v1.3.0
go: downloading github.com/spf13/viper v1.8.1
go: downloading gopkg.in/alecthomas/kingpin.v2 v2.2.6
go: downloading github.com/gorilla/websocket v1.4.2
go: downloading github.com/kopoli/go-terminal-size v0.0.0-20170219200355-5c97524c8b54
go: downloading github.com/minio/pkg v1.0.11
go: downloading golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97
go: downloading github.com/fsnotify/fsnotify v1.4.9
go: downloading github.com/hashicorp/hcl v1.0.0
go: downloading github.com/magiconair/properties v1.8.5
go: downloading github.com/mitchellh/mapstructure v1.4.1
go: downloading github.com/pelletier/go-toml v1.9.3
go: downloading github.com/spf13/afero v1.6.0
go: downloading github.com/spf13/cast v1.3.1
go: downloading github.com/spf13/jwalterweatherman v1.1.0
go: downloading github.com/spf13/pflag v1.0.5
go: downloading github.com/subosito/gotenv v1.2.0
go: downloading gopkg.in/ini.v1 v1.62.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
go: downloading github.com/alecthomas/units v0.0.0-20210208195552-ff826a37aa15
go: downloading github.com/mattn/go-isatty v0.0.13
go: downloading golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1
go: downloading golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1

portainerssh
portainerssh: command not found

Something is missing here because go only seems to download the packages but not install them.

I don't know go and only want to access my containers via "SSH".

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.