Package detail

is-in-ssh

sindresorhus0MIT1.0.0

Check if the process is running in an SSH session

ssh, detect, detection, session

readme

is-in-ssh

Check if the process is running in an SSH session

Useful for determining if your Node.js process is being executed over SSH, which can affect how you handle operations like opening files, browsers, or using system-specific commands.

Install

npm install is-in-ssh

Usage

import isInSsh from 'is-in-ssh';

if (isInSsh) {
    console.log('Running in an SSH session');
}

How it works

The package detects SSH sessions by checking for the presence of standard SSH environment variables:

  • SSH_CONNECTION
  • SSH_CLIENT
  • SSH_TTY

These variables are automatically set by SSH servers when establishing a connection.

Limitations

  • The detection relies on environment variables, which could theoretically be spoofed or cleared
  • May return true for ssh localhost connections (which are technically SSH sessions)
  • Environment variables might not be inherited by all child processes or after privilege escalation (e.g., sudo)

Related

  • is-wsl - Check if the process is running inside Windows Subsystem for Linux
  • is-docker - Check if the process is running inside a Docker container
  • is-inside-container - Check if the process is running inside a container