{"id":18291930,"url":"https://github.com/xxlabaza/sshconfig","last_synced_at":"2025-04-05T10:31:05.269Z","repository":{"id":49715086,"uuid":"375713805","full_name":"xxlabaza/SshConfig","owner":"xxlabaza","description":"An SSH config parser library with a fancy API","archived":false,"fork":false,"pushed_at":"2021-06-20T12:52:06.000Z","size":124,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T03:04:35.110Z","etag":null,"topics":["config","ssh","ssh-config","swift"],"latest_commit_sha":null,"homepage":"https://xxlabaza.github.io/SshConfig","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/xxlabaza.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-10T13:49:20.000Z","updated_at":"2024-12-03T03:09:30.000Z","dependencies_parsed_at":"2022-09-16T10:41:16.288Z","dependency_job_id":null,"html_url":"https://github.com/xxlabaza/SshConfig","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2FSshConfig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2FSshConfig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2FSshConfig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/xxlabaza%2FSshConfig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/xxlabaza","download_url":"https://codeload.github.com/xxlabaza/SshConfig/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247324575,"owners_count":20920676,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config","ssh","ssh-config","swift"],"created_at":"2024-11-05T14:15:46.388Z","updated_at":"2025-04-05T10:31:04.824Z","avatar_url":"https://github.com/xxlabaza.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Platform](https://img.shields.io/badge/platforms-iOS%20%7C%20macOS%20%7C%20tvOS%20%7C%20watchOS%20%7C%20Linux-333333.svg)\n[![Swift](https://img.shields.io/badge/Swift-5.1_5.2_5.3_5.4-green)](https://img.shields.io/badge/Swift-5.1_5.2_5.3_5.4-green)\n[![GitHub license](https://img.shields.io/github/license/xxlabaza/SshConfig)](https://github.com/xxlabaza/SshConfig/blob/main/LICENSE.txt)\n\n[![Build Status](https://github.com/xxlabaza/SshConfig/actions/workflows/tests.yml/badge.svg)](https://github.com/xxlabaza/SshConfig/actions)\n\n[![CocoaPods Compatible](https://img.shields.io/cocoapods/v/SshConfig.svg)](https://img.shields.io/cocoapods/v/SshConfig.svg)\n[![Swift Package Manager](https://img.shields.io/badge/Swift_Package_Manager-compatible-green)](https://img.shields.io/badge/Swift_Package_Manager-compatible-green)\n\n# SshConfig\n\nThe SshConfig makes it quick and easy to load, parse, and decode/encode the SSH configs. It also helps to resolve the properties by hostname and use them safely in your apps (thanks for Optional and static types in Swift).\n\n## Contents\n\n- [Features](#features)\n- [Usage](#usage)\n- [Installation](#installation)\n  - [Requirements](#requirements)\n  - [Swift Package Manager](#swift-package-manager)\n  - [CocoaPods](#cocoapods)\n- [Changelog](#changelog)\n- [Contributing](#contributing)\n- [Versioning](#versioning)\n- [Authors](#authors)\n- [License](#license)\n\n## Features\n\n- Parsing a SSH config;\n- Encode/Decode your config in JSON or text format;\n- Resolve the SSH properties for a host by its alias;\n- The static type checking SSH properties (yeah...If, in the beginning, I knew that there would be almost 100 properties, I would not begin to describe them!).\n\n## Usage\n\nLet's try to load, parse and decode an SSH config file and look at a base scenario of how to work with it.\n\n**~/.ssh/config** file content:\n\n```\nHost gitlab.com github.com\n  PreferredAuthentications publickey\n  IdentityFile ~/.ssh/id_rsa\n  User xxlabaza\n\nHost my*\n  User admin\n  Port 2021\n\nHost *\n  SetEnv POPA=3000\n```\n\nCode example:\n\n```swift\nimport SshConfig\n\nlet config = try! ssh.Config.load(path: \"~/.ssh/config\")\n\nlet github = config.resolve(for: \"github.com\")\nassert(github.preferredAuthentications == [.publickey])\nassert(github.identityFile == [\"~/.ssh/id_rsa\"])\nassert(github.user == \"xxlabaza\")\nassert(github.setEnv == [\"POPA\": \"3000\"]) // from 'Host *'\nassert(github.port == 22) // the default one\n\n// github.com and gitlab.com resolve the same properties set\nassert(github == config.resolve(for: \"gitlab.com\"))\n\nlet myserver = config.resolve(for: \"myserver\")\nassert(myserver.user == \"admin\")\nassert(myserver.port == 2021)\nassert(myserver.setEnv == [\"POPA\": \"3000\"]) // from 'Host *'\n\nlet backend = config.resolve(for: \"backend\")\nassert(backend.user == nil) // the default one\nassert(backend.port == 22) // the default one\nassert(backend.setEnv == [\"POPA\": \"3000\"]) // from 'Host *'\n```\n\nThe same `ssh.Config` instance can be constructed programmatically, like this:\n\n\u003e **NOTE:** I use variadic list of closures for setting needed properties for `ssh.Properties` instance, which creates inside the `ssh.Host` initializer. I found that approach more similar to the original ssh config file format, plus you can ignore the `ssh.Properties`'s fields order.\n\n```swift\nimport SshConfig\n\nlet config = ssh.Config(\n  ssh.Host(\"gitlab.com github.com\",\n    { $0.preferredAuthentications = [.publickey] },\n    { $0.identityFile = [\"~/.ssh/id_rsa\"] },\n    { $0.user = \"xxlabaza\" }\n  ),\n  ssh.Host(\"my*\",\n    { $0.user = \"admin\" },\n    { $0.port = 2021 }\n  ),\n  ssh.Host(\"*\",\n    { $0.setEnv = [\"POPA\": \"3000\"] }\n  )\n)\n\n...\n```\n\nMore code samples and examples are available in the [website](https://xxlabaza.github.io/SshConfig) and in the tests (especially in [UsageExample.swift](https://github.com/xxlabaza/SshConfig/blob/master/Tests/SshConfigTests/UsageExample.swift) file).\n\n## Installation\n\n### Requirements\n\nSwift 5.1+\n\n| iOS | watchOS | tvOS | macOS  |\n|:---:|:-------:|:----:|:------:|\n| 13+ |    6+   |  13+ | 10.15+ |\n\n### Swift Package Manager\n\n\u003e **NOTE:** the instructions below are for using `SwiftPM` without the `Xcode UI`. It's the easiest to go to your Project Settings -\u003e Swift Packages and add SshConfig from there.\n\n[Swift Package Manager](https://swift.org/package-manager/) - **is the recommended installation method**. All you need is to add the following as a dependency to your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/xxlabaza/SshConfig.git\", from: \"1.0.1\"),\n```\n\nSo, your `Package.swift` may look like below:\n\n```swift\n// swift-tools-version:5.1\n\nimport PackageDescription\n\nlet package = Package(\n  name: \"MyPackage\",\n  platforms: [ // The SshConfig requires the versions below as a minimum.\n    .iOS(.v13),\n    .watchOS(.v6),\n    .tvOS(.v13),\n    .macOS(.v10_15),\n  ],\n  products: [\n    .library(name: \"MyPackage\", targets: [\"MyPackage\"]),\n  ],\n  dependencies: [\n    .package(url: \"https://github.com/xxlabaza/SshConfig.git\", from: \"1.0.1\"),\n  ],\n  targets: [\n    .target(name: \"MyPackage\", dependencies: [\"SshConfig\"])\n  ]\n)\n```\n\nAnd then import wherever needed:\n\n```swift\nimport SshConfig\n```\n\n### CocoaPods\n\n[CocoaPods](https://cocoapods.org/) is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate SshConfig into your Xcode project using CocoaPods, specify it in your Podfile:\n\n```ruby\npod 'SshConfig'\n```\n\nEventually, your **Podfile** should look like this one:\n\n```ruby\n# The SshConfig requires the versions below as a minimum.\n# platform :ios, '13.0'\nplatform :osx, '10.15'\n# platform :tvos, '13.0'\n# platform :watchos, '6.0'\n\ntarget 'MyApp' do\n  use_frameworks!\n\n  pod 'SshConfig'\nend\n```\n\nAnd then run:\n\n```\npod install\n```\n\nAfter installing the cocoapod into your project import SshConfig with:\n\n```swift\nimport SshConfig\n```\n\n## Changelog\n\nTo see what has changed in recent versions of the project, see the [changelog](./CHANGELOG.md) file.\n\n## Contributing\n\nPlease read [contributing](./CONTRIBUTING.md) file for details on my code of conduct, and the process for submitting pull requests to me.\n\n## Versioning\n\nI use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/xxlabaza/SshConfig/tags).\n\n## Authors\n\n* **[Artem Labazin](https://github.com/xxlabaza)** - creator and the main developer.\n\n## License\n\nThis project is licensed under the Apache License 2.0 License - see the [license](./LICENSE.txt) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxlabaza%2Fsshconfig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxxlabaza%2Fsshconfig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxxlabaza%2Fsshconfig/lists"}