gitwtfhub

wtf is net-ssh-shell?

mitchellh/net-ssh-shell — explained in plain English

Analysis updated 2026-07-03 · repo last pushed 2015-03-27

79RubyAudience · developerComplexity · 2/5DormantSetup · easy

TL;DR

A Ruby library that keeps a persistent shell session open on a remote server, so commands share state like directory changes and environment variables across multiple executions.

Mindmap

mindmap
  root((repo))
    What it does
      Runs commands remotely
      Keeps shell state
      Supports subshells
    Tech stack
      Ruby
      Net SSH
      RubyGems
    Use cases
      Infrastructure automation
      Deployment scripts
      Config management
    Audience
      Ruby developers
      DevOps engineers
      Automation builders

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Why would anyone build with this?

REASON 1

Write deployment scripts that change directories and set environment variables across multiple commands on a remote server.

REASON 2

Build infrastructure automation tools that need to escalate privileges mid-session using sudo or switch users within a persistent shell.

REASON 3

Create configuration management scripts in Ruby that interact with a remote server conversationally rather than running one-off commands.

What's in the stack?

RubyNet::SSHRubyGems

How it stacks up

mitchellh/net-ssh-shellcrmne/kamal-backupdhh/conductor
Stars797974
LanguageRubyRubyRuby
Last pushed2015-03-272010-09-16
MaintenanceDormantDormant
Setup difficultyeasymoderatemoderate
Complexity2/53/52/5
Audiencedeveloperops devopsdeveloper

Figures from each repo's GitHub metadata at analysis time.

How do you spin it up?

Difficulty · easy Time to first run · 5min

Installs as a standard Ruby gem requiring Net::SSH version 2.

Wtf does this do

Net-ssh-shell is a Ruby library that lets you run commands on a remote server as if you were typing them into the same terminal session. Normally, when you run commands on a remote machine programmatically, each command runs in its own isolated bubble. This library changes that by keeping a single, persistent shell open, so anything you do in one command carries over to the next. The key benefit is statefulness. If you run "cd /usr/local" to change directories and then run "pwd" to see where you are, the second command remembers the directory change from the first. You can also set environment variables in one command and use them in the next. Without this library, you would need to chain everything into a single command or manage complex state tracking yourself. It works as an extension to Net::SSH, a popular Ruby library for connecting to remote servers. You open a connection, start a shell session, and then execute commands one after another within that session. Each command returns an object that includes details like the exit status and the command that was run, so you can check whether things succeeded. The library also supports "subshell" environments, meaning you can switch users or enter a privileged shell like "sudo bash" and continue running commands within that elevated context. This would be useful for anyone building infrastructure automation, deployment scripts, or configuration management tools in Ruby. For example, if you are writing a script that connects to a server, switches to a specific directory, sets some environment variables, and then runs a build command, this library lets you write those steps naturally instead of cramming them into a single line. It is also handy for scenarios where you need to escalate privileges mid-session or interact with shells that expect a ongoing conversation rather than one-off commands. The project is relatively small and focused, doing one thing well rather than trying to be a full automation framework. It requires Net::SSH version 2 and installs as a standard Ruby gem.

Yoink these prompts

Prompt 1
Help me write a Ruby script using net-ssh-shell that connects to a remote server, changes to /var/www/myapp, sets RAILS_ENV=production, and runs a deploy command, all in the same persistent shell session.
Prompt 2
Show me how to use net-ssh-shell to open a Net::SSH connection, start a subshell with 'sudo bash', and then run multiple commands in that elevated privileged context.
Prompt 3
Write a Ruby deployment script using net-ssh-shell that SSHes into a server, checks the exit status of each command, and stops the deploy if any command fails.

Frequently asked questions

wtf is net-ssh-shell?

A Ruby library that keeps a persistent shell session open on a remote server, so commands share state like directory changes and environment variables across multiple executions.

What language is net-ssh-shell written in?

Mainly Ruby. The stack also includes Ruby, Net::SSH, RubyGems.

Is net-ssh-shell actively maintained?

Dormant — no commits in 2+ years (last push 2015-03-27).

How hard is net-ssh-shell to set up?

Setup difficulty is rated easy, with roughly 5min to a first successful run.

Who is net-ssh-shell for?

Mainly developer.

View the repo → Decode another repo

This repo across BitVibe Labs

Don't trust strangers blindly. Verify against the repo.