The `ssh-config` library offers robust parsing and stringification capabilities for SSH configuration files, typically located at `~/.ssh/config`. As of its current stable version, 5.1.0, it enables developers to programmatically read, modify, and write SSH configurations while diligently preserving original formatting, comments, and whitespace. The project maintains an active release cadence, frequently addressing bugs and introducing features, such as Deno support in v5.1.0 and continuous improvements to TypeScript typings. Its primary differentiator lies in its ability to parse an SSH config into an Abstract Syntax Tree (AST)-like structure for easy manipulation and then reliably serialize it back into a valid SSH config string, ensuring changes are applied correctly without data loss. Additionally, it provides convenient helper methods like `compute` to derive the effective configuration for a specific host, and `find` for targeted section modification, offering granular control over SSH settings.
npm install ssh-configVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates parsing an SSH config string, modifying an existing host entry, adding a new host, computing effective parameters for a host, and finally stringifying the updated configuration.
Review any code that programmatically modifies or expects specific formatting of values with quotation marks. Adjust parsing or stringification logic if relying on previous behavior.
When using `config.compute(host)`, always pass `{ ignoreCase: true }` as the second argument if you require case-normalized output keys (e.g., `hostname` instead of `hOsTnaME`).Ensure that general settings are placed at the end of your SSH config file so they act as defaults, and more specific host-based settings override them earlier in the file.
Always expect `IdentityFile` to be an array when accessing it from the output of `config.compute()`. Iterate over the array even if you anticipate a single value.
Use `config.find({ Host: 'name' })` only when you intend to modify the structure or parameters of a specific host section directly. For retrieving the final, applied SSH configuration for a host, always use `config.compute('hostname')`.Ensure the input string to `SSHConfig.parse()` is a valid, non-empty SSH configuration. Version 5.0.4 fixed a crash on empty files, but robust error handling for invalid formats is still recommended.
Update to `ssh-config@^5.0.1` or later, as `v5.0.1` specifically addressed wrong typings for the `compute` method. Ensure your `tsconfig.json` includes `"allowSyntheticDefaultImports": true` if using `import SSHConfig from 'ssh-config'`.
Version 4.4.3 specifically addressed this. Ensure you are on `ssh-config@^4.4.3` or newer. If the issue persists in highly restrictive environments, you might need to mock `os.userInfo()` or ensure the execution environment provides necessary user context.
No dependency data recorded yet.