{"name":"ssh-config","description":"SSH config parser and stringifier","version":"5.3.0","author":{"name":"Chen Yangjian","url":"https://www.cyj.me"},"repository":{"type":"git","url":"git+https://github.com/cyjake/ssh-config.git"},"type":"module","types":"./lib/ssh-config.d.ts","devDependencies":{"@biomejs/biome":"2.5.11","@types/node":"^26.2.0","@types/sinon":"^22.0.0","c8":"^12.0.0","sinon":"^22.1.0","typescript":"^7.0.2"},"scripts":{"lint":"biome lint .","lint:fix":"biome lint --write .","build":"tsc && tsc -p tsconfig.cjs.json && node scripts/write-package-metadata.cjs","prepack":"npm run build","pretest":"npm run build","test":"node --experimental-transform-types --test test/unit/*.test.ts","test:coverage":"c8 --reporter=text --reporter=lcov --check-coverage --lines=90 node --experimental-transform-types --test test/unit/*.test.ts","test:legacy":"node --experimental-transform-types --test test/legacy/*.test.ts","test:legacy:coverage":"c8 --reporter=text --reporter=lcov --check-coverage --lines=90 node --experimental-transform-types --test test/legacy/*.test.ts","test:exports":"node test/package-exports.cjs","test:package":"node scripts/test-package.mjs","release:check":"node scripts/check-release.mjs"},"main":"dist/ssh-config.js","exports":{".":{"types":"./lib/ssh-config.d.ts","import":"./lib/ssh-config.js","require":"./dist/ssh-config.js"}},"engines":{"node":">= 14.18.0"},"license":"MIT","gitHead":"929aad8dd70d89f41082b55a4aa4b51deed11b98","_id":"ssh-config@5.3.0","bugs":{"url":"https://github.com/cyjake/ssh-config/issues"},"homepage":"https://github.com/cyjake/ssh-config#readme","_nodeVersion":"24.20.0","_npmVersion":"11.19.0","dist":{"integrity":"sha512-JIsoWax2CAJraGLvhXa4e9zfh+/KzoL6SKxjupQywLjGpuigYsZ+5OVmfZo1mBslxehA8kHWwFQ38eotFoLj6Q==","shasum":"9945936329832f2aa551fe58e8d1e7bb401c51ff","tarball":"http://registry-npm.ywwl.com/ssh-config/download/ssh-config-5.3.0.tgz","fileCount":17,"unpackedSize":169152,"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/ssh-config@5.3.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCID5kPzKkImWQ4Mo0PJBcGRP/Kplql7kMDntXigRHL0v2AiBhA522eR6mBe1xNxOZo6Q9kX57CqJ53mj719kx+bzTxQ=="}],"size":33131,"noattachment":false,"key":"/ssh-config/-/ssh-config-5.3.0.tgz"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4290568f-828f-43d7-b947-c644aacb15fe"}},"directories":{},"maintainers":[{"name":"dotnil","email":"jakeplus@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/ssh-config_5.3.0_1789139038542_0.9497818507719893"},"_hasShrinkwrap":false,"readme":"# SSH Config Parser & Stringifier\n\n[![NPM Downloads](https://img.shields.io/npm/dm/ssh-config.svg?style=flat)](https://www.npmjs.com/package/ssh-config)\n[![NPM Version](http://img.shields.io/npm/v/ssh-config.svg?style=flat)](https://www.npmjs.com/package/ssh-config)\n![JSR Version](https://img.shields.io/jsr/v/%40cyjake/ssh-config)\n[![Build Status](https://travis-ci.org/cyjake/ssh-config.svg)](https://travis-ci.org/cyjake/ssh-config)\n[![Deno CI](https://github.com/cyjake/ssh-config/actions/workflows/deno.yml/badge.svg)](https://github.com/cyjake/ssh-config/actions/workflows/deno.yml)\n[![Node CI](https://github.com/cyjake/ssh-config/actions/workflows/nodejs.yml/badge.svg)](https://github.com/cyjake/ssh-config/actions/workflows/nodejs.yml)\n[![codecov](https://codecov.io/gh/cyjake/ssh-config/branch/master/graph/badge.svg?token=RMyTgcL8Kg)](https://codecov.io/gh/cyjake/ssh-config)\n\n## Usage\n\n```js\nconst SSHConfig = require('ssh-config')\n\nconst config = SSHConfig.parse(`\n  IdentityFile ~/.ssh/id_rsa\n\n  Host tahoe\n    HostName tahoe.com\n\n  Host walden\n    HostName waldenlake.org\n\n  Host *\n    User keanu\n    ForwardAgent true\n`)\n\nexpect(config).to.eql(\n  [ { \"param\": \"IdentityFile\",\n      \"value\": \"~/.ssh/id_rsa\" },\n    { \"param\": \"Host\",\n      \"value\": \"tahoe\",\n      \"config\":\n        [ { \"param\": \"HostName\",\n            \"value\": \"tahoe.com\" } ] },\n    { \"param\": \"Host\",\n      \"value\": \"walden\",\n      \"config\":\n        [ { \"param\": \"HostName\",\n            \"value\": \"waldenlake.org\" } ] },\n    { \"param\": \"Host\",\n      \"value\": \"*\",\n      \"config\":\n        [ { \"param\": \"User\",\n            \"value\": \"keanu\" },\n          { \"param\": \"ForwardAgent\",\n            \"value\": \"true\" } ] } ]\n)\n\n// Change the HostName in the Host walden section\nconst section = config.find({ Host: 'walden' })\n\nfor (const line of section.config) {\n  if (line.param === 'HostName') {\n    line.value = 'waldenlake.org'\n    break\n  }\n}\n\n// The original whitespaces and comments are preserved.\nconsole.log(SSHConfig.stringify(config))\n// console.log(config.toString())\n```\n\n### Iterating over Sections\n\nOne needs to iterate over ssh configs mostly because of two reasons.\n\n- to `.find` the corresponding section and modify it, or\n- to `.compute` the ssh config about certain `Host`.\n\n\n### `.compute` Parameters by Host\n\nYou can use `config.compute` method to compute applied parameters of certain host.\n\n```js\nexpect(config.compute('walden')).to.eql({\n  IdentityFile: [\n    '~/.ssh/id_rsa'\n  ],\n  Host: 'walden',\n  HostName: 'waldenlake.org',\n  User: 'nil',\n  ForwardAgent: 'true'\n})\n```\n\n**NOTICE** According to [ssh_config(5)][ssh_config], the first obtained\nparameter value will be used. So we cannot override existing parameters. It is\nsuggested that the general settings shall be at the end of your config file.\n\nThe `IdentityFile` parameter always contain an array to make possible multiple\n`IdentityFile` settings to be able to coexist.\n\n#### Case-Insensitive Matching\n\nOpenSSH treats configuration directives case-insensitively. By default, `compute()`\npreserves the original case from the config file. To normalize directive names to\nlowercase (matching OpenSSH behavior), use the `ignoreCase` option:\n\n```js\nconst config = SSHConfig.parse(`\n  Host example\n    hOsTnaME 1.2.3.4\n    USER admin\n`)\n\n// Default - preserves original case\nconfig.compute('example')\n// => { hOsTnaME: '1.2.3.4', USER: 'admin' }\n\n// With ignoreCase - lowercase to match OpenSSH\nconfig.compute('example', { ignoreCase: true })\n// => { hostname: '1.2.3.4', user: 'admin' }\n\n#### Match Exec\n\n`Match exec` criteria are evaluated by default to match OpenSSH behavior. If\nthe config text may be untrusted, pass `{ matchExec: false }` to skip\n`Match exec` sections while still computing `Host` sections and non-exec\n`Match` criteria:\n\n```js\nconfig.compute('walden', { matchExec: false })\n```\n\n### `.find` sections by Host or Match\n\n**NOTICE**: This method is provided to find the corresponding section in the\nparsed config for config manipulation. It is NOT intended to compute config\nof certain Host. For latter case, use `.compute(host)` instead.\n\nTo ditch boilerplate codes like the for loop shown earlier, we can use the\n`.find(opts)` available in the parsed config object.\n\n```js\nconfig.find({ Host: 'example1' })\n// or the ES2015 Array.prototype.find\nconfig.find(line => line.param == 'Host' && line.value == 'example1')\n```\n\n### `.remove` sections by Host / Match or function\n\nTo remove sections, we can pass the section to `.remove(opts)`.\n\n```js\nconfig.remove({ Host: 'example1' })\n// or the ES2015 Array.prototype.find\nconfig.remove(line => line.param == 'Host' && line.value == 'example1')\n```\n\n### `.append` sections\n\nSince the parsed config is a sub class of Array, you can append new sections with methods like `.push` or `.concat`.\n\n```js\nconfig.push(...SSHConfig.parse(`\nHost ness\n  HostName lochness.com\n  User dinosaur\n`))\n\nexpect(config.find({ Host: '*' })).to.eql(\n  { \"param\": \"Host\",\n    \"value\": \"ness\",\n    \"config\":\n     [ { \"param\": \"HostName\",\n         \"value\": \"lochness.com\" } ] }\n)\n```\n\nIf the section to append is vanilla JSON, `.append` is what you need.\n\n```js\nconst config = new SSHConfig()\n\nconfig.append({\n  Host: 'ness',\n  HostName: 'lochness.com',\n  User: 'dinosaur'\n})\n\nSSHConfig.stringify(config)\n// =>\n// Host ness\n//   HostName lochness.com\n//   User dinosaur\n```\n\n### `.prepend` sections\n\nBut appending options to the end of the config isn't very effective if your config is organizated per the recommendations of ssh_config(5) that the generic options are at at the end of the config, such as:\n\n```\nHost ness\n  HostName lochness.com\n  User dinosaur\n\nIdentityFile ~/.ssh/id_rsa\n```\n\nThe config could get messy if you put new options after the line of `IdentityFile`. To work around this issue, it is recommended that `.prepend` should be used instead. For the example above, we can prepend new options at the beginning of the config:\n\n```js\nconfig.prepend({\n  Host: 'tahoe',\n  HostName 'tahoe.com',\n})\n```\n\nThe result would be:\n\n```\nHost tahoe\n  HostName tahoe.com\n\nHost ness\n  HostName lochness.com\n  User dinosaur\n\nIdentityFile ~/.ssh/id_rsa\n```\n\nIf there are generic options at the beginning of the config, and you'd like the prepended section put before the first existing section, please turn on the second argument of `.prepend`:\n\n```js\nconfig.prepend({\n  Host: 'tahoe',\n  HostName 'tahoe.com',\n}, true)\n```\n\nThe result would be like:\n\n```\nIdentityFile ~/.ssh/id_rsa\n\nHost tahoe\n  HostName tahoe.com\n\nHost ness\n  HostName lochness.com\n  User dinosaur\n```\n\n## References\n\n- [ssh_config(5)][ssh_config]\n- [ssh_config(5)][ssh_config_die]\n- [ssh_config(5) OpenBSD][ssh_config_openbsd]\n- http://en.wikibooks.org/wiki/OpenSSH/Client_Configuration_Files#.7E.2F.ssh.2Fconfig\n- http://stackoverflow.com/questions/10197559/ssh-configuration-override-the-default-username\n\n\n[ssh_config]: https://www.freebsd.org/cgi/man.cgi?query=ssh_config&sektion=5\n[ssh_config_die]: http://linux.die.net/man/5/ssh_config\n[ssh_config_openbsd]: http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/ssh_config.5?query=ssh_config&arch=i386\n","publish_time":1789139038685,"_cnpm_publish_time":1789139038685,"dist-tags":{"latest":"5.3.0"}}