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.
npm install is-in-ssh
import isInSsh from 'is-in-ssh';
if (isInSsh) {
console.log('Running in an SSH session');
}
The package detects SSH sessions by checking for the presence of standard SSH environment variables:
SSH_CONNECTIONSSH_CLIENTSSH_TTYThese variables are automatically set by SSH servers when establishing a connection.
true for ssh localhost connections (which are technically SSH sessions)sudo)