# is-in-ssh

> Check if the process is running in an SSH session

Latest version **1.0.0** (published 2025-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-in-ssh
pnpm add is-in-ssh
yarn add is-in-ssh
bun add is-in-ssh
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2025-11-12 |
| First published | 2025-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 3.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Sindre Sorhus |
| Maintainers | sindresorhus |
| Keywords | ssh, detect, detection, session, remote, connection, environment, check, is |

## Links

- npm: https://www.npmjs.com/package/is-in-ssh
- Repository: https://github.com/sindresorhus/is-in-ssh
- Homepage: https://github.com/sindresorhus/is-in-ssh#readme
- Issues: https://github.com/sindresorhus/is-in-ssh/issues
- Funding: https://github.com/sponsors/sindresorhus
- npm.io page: https://npm.io/package/is-in-ssh

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2025-11-12

## 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

```sh
npm install is-in-ssh
```

## Usage

```js
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](https://github.com/sindresorhus/is-wsl) - Check if the process is running inside Windows Subsystem for Linux
- [is-docker](https://github.com/sindresorhus/is-docker) - Check if the process is running inside a Docker container
- [is-inside-container](https://github.com/sindresorhus/is-inside-container) - Check if the process is running inside a container

---
_Source: https://npm.io/package/is-in-ssh · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
