{"library":"ssh-config","title":"SSH Config Parser and Stringifier","type":"library","description":"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.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install ssh-config"],"cli":null},"imports":["import SSHConfig from 'ssh-config'","import SSHConfig from 'ssh-config'; SSHConfig.parse(configString)","import { LineType } from 'ssh-config'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/cyjake/ssh-config","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/ssh-config","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import SSHConfig from 'ssh-config';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nconst configContent = `\n# This is a comment\nIdentityFile ~/.ssh/id_rsa\n\nHost devserver\n  HostName 192.168.1.100\n  User admin\n\nHost *\n  User keanu\n  ForwardAgent true\n`;\n\n// Parse the SSH config string\nconst config = SSHConfig.parse(configContent);\n\n// Find and modify a specific host section\nconst devserverSection = config.find({ Host: 'devserver' });\nif (devserverSection && devserverSection.config) {\n  for (const line of devserverSection.config) {\n    if (line.param === 'HostName') {\n      line.value = 'dev.example.com';\n      break;\n    }\n  }\n}\n\n// Add a new host section\nconfig.add({\n  Host: 'staging',\n  config: [\n    { param: 'HostName', value: 'staging.example.com' },\n    { param: 'User', value: 'deploy' }\n  ]\n});\n\n// Compute the effective configuration for a host\nconst computedConfig = config.compute('staging', { ignoreCase: true });\nconsole.log('Computed config for staging:', computedConfig);\n\n// Stringify the modified configuration back to a string\nconst newConfigString = SSHConfig.stringify(config);\nconsole.log('\\n--- Modified SSH Config ---\\n');\nconsole.log(newConfigString);\n\n// Example: writing to a temporary file (ensure directory exists)\nconst tempDir = path.join(process.cwd(), 'temp');\nif (!fs.existsSync(tempDir)) {\n  fs.mkdirSync(tempDir);\n}\nconst tempConfigFile = path.join(tempDir, 'ssh_config_modified.tmp');\nfs.writeFileSync(tempConfigFile, newConfigString);\nconsole.log(`\\nModified config written to: ${tempConfigFile}`);","lang":"typescript","description":"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}