{"name":"ssh-config","version":"5.0.4","author":{"url":"https://www.cyj.me","name":"Chen Yangjian"},"license":"MIT","_id":"ssh-config@5.0.4","maintainers":[{"name":"dotnil","email":"jakeplus@gmail.com"}],"homepage":"https://github.com/cyjake/ssh-config#readme","bugs":{"url":"https://github.com/cyjake/ssh-config/issues"},"dist":{"shasum":"bea2251fd9ed7acbaed32cfd5c8cd08dc44aa9cd","tarball":"http://registry-npm.ywwl.com/ssh-config/download/ssh-config-5.0.4.tgz","fileCount":12,"integrity":"sha512-nCCJTY30Alhm8CWhhN8Yr1YAx2WOrDBLMMh7JYGrzCj3qssTPV+v10hYimd+8wJJeV10VrN8lFumawAEfEwjNA==","signatures":[{"sig":"MEUCICnYoVs/Sy5FZ1NoDWTJZ82BOOL+4NOFV4/2SqP/vF+PAiEAnosjMh8yKsMv6DCswSGgrjoHcdtGcqtAgblmqeHEHJY=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/ssh-config@5.0.4","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":55818,"size":14062,"noattachment":false,"key":"/ssh-config/-/ssh-config-5.0.4.tgz"},"main":"dist/index.js","types":"dist/index.d.ts","engine":{"node":">= 14.0.0"},"gitHead":"1886ec65d8e2cb4e734ca6d74a3277573a0763c4","scripts":{"lint":"eslint --ext ts .","test":"mocha","build":"tsc","prepack":"npm run build","pretest":"npm run build","lint:fix":"eslint --ext ts --fix .","test:coverage":"nyc mocha && nyc report --reporter=lcov"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4290568f-828f-43d7-b947-c644aacb15fe"}},"repository":{"url":"git+ssh://git@github.com/cyjake/ssh-config.git","type":"git"},"_npmVersion":"11.6.2","description":"SSH config parser and stringifier","directories":{},"_nodeVersion":"24.11.1","_hasShrinkwrap":false,"devDependencies":{"nyc":"^15.1.0","mocha":"^8.2.1","sinon":"^17.0.1","eslint":"^8.31.0","heredoc":"^1.3.1","ts-node":"^10.9.2","typescript":"^5.4.4","@types/node":"^17.0.45","@types/mocha":"^9.1.0","@types/sinon":"^17.0.3","@typescript-eslint/parser":"^5.48.0","@typescript-eslint/eslint-plugin":"^5.48.0"},"_npmOperationalInternal":{"tmp":"tmp/ssh-config_5.0.4_1763298980231_0.03720527715611799","host":"s3://npm-registry-packages-npm-production"},"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":1763298980440,"_cnpm_publish_time":1763298980440,"dist-tags":{"latest":"5.3.0"}}