Skip to content

andy-netgenius/panssh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

74 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ–₯️ PanSSH

An emulated SSH login for Pantheon sites

PanSSH emulates an interactive SSH connection to a Pantheon site's application environment using only their available (limited) SSH service. It provides command history, local editing of remote files and an emulated current working directory.

You can do almost everything that you could if a standard SSH login were available, and it looks and feels so familiar that you may not notice the difference.

Quick start

Download and run the main script
curl -so panssh https://github.com/andy-netgenius/panssh/raw/refs/tags/latest/panssh
chmod +x panssh
./panssh

Further instructions will then be displayed.

Recent changes

  • 1.3.1:
    • Added .copy, .copyr and .rsync built-in commands to copy/sync directories to/from the remote site.
    • Various minor fixes and improvements.
  • 1.2.1:
  • 1.2.0: Tab-completion is now included, on supporting systems:
    • Local site and environment names.
    • Remote directory and file names.

πŸ“Œ Usage

Interactive

panssh site.env

Non-Interactive

From command-line:
panssh site.env "command1; command2; ..."
From stdin:
panssh site.env < script.sh
echo "commands" | panssh site.env
  • site β€” the Pantheon site name.
  • env β€” the environment identifier (dev, test, live, or multidev ID).

🧰 Commands

Standard

  • Use shell commands in the normal way.
  • Type exit to close the interactive session.

Built-in commands

  • .help β€” Display usage information and command list.

  • .vw <filepath> β€” View a remote file (download and open in viewer/editor).

  • .ed <filepath> β€” Edit a remote file (download, edit locally, upload).

  • .ls β€” Toggle automatic ls after directory change.

  • .copy [local:]<source> [local:]<target> β€” Copy files to/from the remote site.

  • .copyr [local:]<source> [local:]<target> β€” Recursively copy directories/files to/from the remote site.

  • .rsync [options] [local:]<source> [local:]<target> β€” Run rsync.

Copying directories and files to or from the remote site.

  • The .copy command runs rsync with its preserve modification times, compress and progress options enabled.

  • The .copyr command adds rsync's recursive option, but is otherwise identical to .copy.

  • The .rsync command runs rsync with only the options you specify.

All three commands require that either the source or target path be prefixed by local: in order to indicate the required transfer direction.

Examples:

To the copy the local file settings.php to the remote current directory you could use:

.copy local:settings.php ./

To recursively copy all files and sub-directories from remote path web/sites/default/files/ to local path /tmp/files/ you could use:

.copyr web/sites/default/files/ local:/tmp/files/

βœ… Requirements

  • A Pantheon user account with SSH access configured.
  • SSH client with a key pair registered in your Pantheon account.
  • Bash 3.2+ for basic operation.
  • Bash 4.0+ to support tab-completion of remote directory and file names.
  • Common Linux/Unix utilities.
  • For local file viewing / editing:
    • Either nano or vim available via $PATH$, or a suitably configured $EDITOR.
    • Standard scp and shasum utilities.
  • For copying files to/from remote: rsync.
  • Terminus CLI (needed only to fetch a list of your accessible sites).

πŸ“¦ Installation

No installation

The only required file is the panssh script.

Download just the main script
curl -so panssh https://github.com/andy-netgenius/panssh/raw/refs/tags/latest/panssh
  • Mark the script as executable: chmod +x panssh
  • Run it as just ./panssh to see further instructions.

Minimal installation

Clone the PanSSH repository or download and unzip the zip archive.

Mark the main panssh script as executable, then copy or move it to any suitable directory that's included in your PATH.

chmod +x panssh
sudo mv panssh /usr/local/bin/

Run it as just panssh to see further instructions.

Optional: tab-completion of local site and environment names

Copy the panssh completion script from bash-completion/ to the bash-completions/completions directory on your system.

  • For recent Ubuntu distributions, you can probably use /usr/local/share/bash-completion/completions/
  • For MacOS, maybe /opt/homebrew/etc/bash_completion.d/ or usr/local/etc/bash_completion.d, depending on your system.

Test tab-completion by entering panssh then pressing the tab key (create a sites configuration file first).

Optional: tab-completion of remote directory and file names

This feature requires Bash 4 or higher.

Copy readx.source.sh to one of:

  • The same location as the main panssh script.
  • A subdirectory ../lib/panssh relative to the location of the main panssh script.
    • For example: /usr/local/lib/panssh/ if panssh itself is in /usr/local/bin/

Test tab-completion by using panssh to connect to a Pantheon site, then press the tab key once or twice - the remote directory contents should be listed.


βš™οΈ Configuration

A simple CSV file holding name and ID of the sites you want to connect to is required at:

$HOME/.panssh.sites

To generate or update it, run:

terminus site:list --format=csv --fields=name,id > $HOME/.panssh.sites

This file maps Pantheon site names to their site IDs, which are used to form SSH host and user names.


✨ Features

  • Most things will just work as you would expect. A few won't (see limitations, below).
  • Local viewing and editing of remote files, with automatic download and upload.
  • Non-interactive execution from local scripts or piped input.
  • Arrow-key command history for the current session.
  • Local tab-completion of site and environment names.
  • Tab-completion of remote directory and file names.
  • Optional automatic listing of directory contents after switching directory.
  • Uses persistent SSH connections for best responsiveness.

⚠️ Limitations

  • No support for interactive input (more, rm -i, drush confirmation prompts, etc). Some such programs will act as if ENTER was pressed and use a default value. Others will simply not work.
  • Some behaviours will differ compared with a real interactive SSH session.
  • Tab-completion for remote directory and file names requires Bash 4+.
  • Relies on discoverable but publicly undocumented features of Pantheon's SSH service, and their user and host naming conventions.

πŸ‘€ Author

Andy Inman
ainman@netgenius.co.uk


πŸͺͺ License

MIT

About

Pantheon Interactive SSH Session Emulator

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages