# sshconfig-lint
[](https://github.com/Noah4ever/sshconfig-lint/actions/workflows/tests.yml)
[](https://crates.io/crates/sshconfig-lint)
[](LICENSE)
**SSH 設定が変更されるあらゆる場所に対応する単一のエンジン。**
sshconfig-lint は OpenSSH クライアント設定の意味的な誤りを検出します。重複したホスト、壊れた identity パス、安全でないオプション、弱いアルゴリズム、ワイルドカードの順序、絡み合った `Include` チェーンなどです。同じルールコードをローカル、Git フック、GitHub Actions、エディタで使用できます。
[プライベートブラウザプレイグラウンドを試す](https://sshconfig-lint.apps.thiering.org/en) · [インタラクティブな例で学ぶ](https://sshconfig-lint.apps.thiering.org/en/learn) · [すべてのルールを読む](https://sshconfig-lint.apps.thiering.org/en/rules)
ブラウザチェッカーはお使いのデバイス上で動作します。設定内容はアップロードされず、テレメトリも収集されません。
## クイックスタート
```bash
# check ~/.ssh/config
sshconfig-lint
# check one or more repository configs
sshconfig-lint .ssh/config infrastructure/ssh_config
# fail on warnings and errors
sshconfig-lint .ssh/config --strict
```
## インストール
### Homebrew
```bash
brew tap Noah4ever/tap
brew install sshconfig-lint
```
### Cargo
```bash
cargo install sshconfig-lint
```
### Arch Linux
```bash
yay -S sshconfig-lint-bin
```
[リリースページ](https://github.com/Noah4ever/sshconfig-lint/releases)では、Linux、macOS、Windows 用の検証済みバイナリを提供しています。便利なインストーラーはインストール前にリリースチェックサムを検証します:
```bash
curl -fsSL https://raw.githubusercontent.com/Noah4ever/sshconfig-lint/main/install.sh | bash
```
デフォルトを上書きするには `VERSION=v0.5.0` または `INSTALL_DIR=~/.local/bin` を設定します。
## GitHub Actions
公式 Action は
[GitHub Marketplace](https://github.com/marketplace/actions/sshconfig-lint) で利用できます。
```yaml
name: SSH config
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: Noah4ever/[email protected]
with:
paths: |
.ssh/config
infrastructure/ssh_config
strict: true
```
検出結果は正確なファイルと行にアノテーションとして表示されます。Action はタグに一致するリリースをダウンロードし、実行前に `SHA256SUMS` を検証します。
GitHub Code Scanning が有効なリポジトリでは、SARIF を別途アップロードできます:
```yaml
- run: sshconfig-lint .ssh/config --format sarif > sshconfig-lint.sarif
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: sshconfig-lint.sarif
```
## Pre-Commit
```yaml
repos:
- repo: https://github.com/Noah4ever/sshconfig-lint
rev: v1.0.0
hooks:
- id: sshconfig-lint-strict
```
警告でコミットをブロックしたくない場合は `id: sshconfig-lint` を使用します。設定が別の命名規則を使用している場合は、プロジェクトで `files:` を上書きしてください。
## エディタ
### VS Code
Marketplace から [VS Code 拡張機能](https://marketplace.visualstudio.com/items?itemName=NoahThiering.sshconfig-lint)をインストールするか、次を実行します:
```bash
code --install-extension NoahThiering.sshconfig-lint
```
この拡張機能は `sshconfig-lint lsp` を起動し、一致する検証済みバイナリを一度ダウンロードした後、オフラインで動作します。`.ssh/config`、`ssh_config`、chezmoi の `dot_ssh/config` を認識します。テレメトリは収集されません。ソースは [`editors/vscode`](https://github.com/noah4ever/sshconfig-lint/blob/main/editors/vscode) で入手できます。
### Neovim
テスト済みの [`editors/neovim`](https://github.com/noah4ever/sshconfig-lint/blob/main/editors/neovim) の例は、Neovim 組み込みの
LSP クライアントを使用します。その小さな Lua モジュールを設定にコピーし、次のように起動します:
```lua
require("sshconfig_lint").setup()
```
VS Code と同じ `sshconfig-lint lsp` サーバーを使用し、カスタムの
バイナリパスをサポートします。
LSP をサポートする任意のエディタは次で起動できます:
```bash
sshconfig-lint lsp
```
v0.5 の言語サーバーは、開く、変更、保存時に全行の診断を発行します。無題のバッファはコンテンツのみのルールを実行し、保存されたファイルはさらに `Include` とファイルシステムパスを解決します。ネストされた Include からの検出結果は、インクルードされたファイルに添付され、ルートドキュメントとともにクリアされます。
## 出力形式
```bash
sshconfig-lint --format text
sshconfig-lint --format json
sshconfig-lint --format github
sshconfig-lint --format sarif
```
JSON の検出結果には `severity`、`code`、`rule`、`line`、`file`、`message`、`hint`、`documentation` が含まれます。ルールコードと終了コードは安定した自動化インターフェースです。
| 終了コード | 意味 |
|---:|---|
| `0` | エラーレベルの検出結果がなく、`--strict` 使用時は警告もない |
| `1` | 少なくとも 1 つのブロックする検出結果がある |
| `2` | 要求された設定のうち少なくとも 1 つが読み取れなかった |
## ルール
| コード | ルール | 重大度 |
|---|---|---|
| `INVALID_VALUE` | [無効なディレクティブ値](https://sshconfig-lint.apps.thiering.org/en/rules/invalid-directive-value) | error |
| `DUP_HOST` | [重複した Host ブロック](https://sshconfig-lint.apps.thiering.org/en/rules/duplicate-host) | warning |
| `MISSING_IDENTITY` | [IdentityFile が見つからない](https://sshconfig-lint.apps.thiering.org/en/rules/identity-file-exists) | error |
| `WILDCARD_ORDER` | [Host ワイルドカードの順序](https://sshconfig-lint.apps.thiering.org/en/rules/wildcard-host-order) | warning |
| `WEAK_ALGO` | [弱いアルゴリズム](https://sshconfig-lint.apps.thiering.org/en/rules/deprecated-weak-algorithms) | warning |
| `DUP_DIRECTIVE` | [重複したディレクティブ](https://sshconfig-lint.apps.thiering.org/en/rules/duplicate-directives) | warning |
| `INSECURE_OPT` | [安全でないオプション](https://sshconfig-lint.apps.thiering.org/en/rules/insecure-option) | warning |
| `UNSAFE_CTRL_PATH` | [安全でない ControlPath](https://sshconfig-lint.apps.thiering.org/en/rules/unsafe-control-path) | warning |
| `INCLUDE_CYCLE` | [Include の循環](https://sshconfig-lint.apps.thiering.org/en/rules/include-cycle) | error |
| `INCLUDE_DEPTH` | [Include のネストが深すぎる](https://sshconfig-lint.apps.thiering.org/en/rules/include-depth) | error |
| `INCLUDE_READ` | [Include を読み取れない](https://sshconfig-lint.apps.thiering.org/en/rules/include-read) | error |
| `INCLUDE_GLOB` | [無効な Include パターン](https://sshconfig-lint.apps.thiering.org/en/rules/include-glob) | error |
| `INCLUDE_NO_MATCH` | [Include がどのファイルにも一致しない](https://sshconfig-lint.apps.thiering.org/en/rules/include-no-match) | info |
| `NEGATED_HOST` | [Host に否定パターンのみがある](https://sshconfig-lint.apps.thiering.org/en/rules/negated-only-host) | warning |
| `PROXY_CONFLICT` | [ProxyCommand と ProxyJump の競合](https://sshconfig-lint.apps.thiering.org/en/rules/proxy-command-jump-conflict) | warning |
| `REVOKED_HOST_KEYS_UNREADABLE` | [RevokedHostKeys ファイルが読み取れない](https://sshconfig-lint.apps.thiering.org/en/rules/revoked-host-keys-readable) | error |
| `MISSING_CERTIFICATE` | [CertificateFile が見つからない](https://sshconfig-lint.apps.thiering.org/en/rules/certificate-file-exists) | error |
| `LOCAL_COMMAND_DISABLED` | [LocalCommand が有効になっていない](https://sshconfig-lint.apps.thiering.org/en/rules/local-command-enabled) | warning |
| `INVALID_TOKEN` | [無効なパーセントトークン](https://sshconfig-lint.apps.thiering.org/en/rules/invalid-percent-token) | error |
| `INVALID_SYNTAX` | [無効な構文](https://sshconfig-lint.apps.thiering.org/en/rules/invalid-syntax) | error |
| `UNKNOWN_DIRECTIVE` | [不明なディレクティブ](https://sshconfig-lint.apps.thiering.org/en/rules/unknown-directive) | error |
| `DEPRECATED_OPTION` | [非推奨のオプション](https://sshconfig-lint.apps.thiering.org/en/rules/deprecated-option) | warning |
| `INVALID_MATCH` | [無効な Match 条件](https://sshconfig-lint.apps.thiering.org/en/rules/invalid-match-condition) | error |
| `CONTROL_PERSIST_UNUSED` | [ControlMaster なしの ControlPersist](https://sshconfig-lint.apps.thiering.org/en/rules/control-persist-requires-master) | warning |
| `UPDATE_HOSTKEYS_ASK_PERSIST` | [ControlPersist を伴う UpdateHostKeys ask](https://sshconfig-lint.apps.thiering.org/en/rules/update-hostkeys-control-persist) | warning |
ルールガイドでは、正確な壊れたフラグメント、修正された設定、なぜ重要か、OpenSSH で結果を検証する方法を示します。
`INVALID_VALUE` は、ポート、リトライおよびプロンプトカウンター、alive 設定、`ForwardX11Timeout`、`RequiredRSASize`、`ControlPersist`、ブールスイッチ、`ObscureKeystrokeTiming`、OpenSSH 時間値、`StreamLocalBindMask`、`IPQoS`、および `AddressFamily`、`ControlMaster`、`StrictHostKeyChecking`、`LogLevel`、`PubkeyAuthentication` などの文書化された値セットをチェックします。OpenSSH が受け入れる引用符付きおよび大文字小文字を区別しない値は有効なままです。リンターは、設定を消費する SSH クライアントのバージョンを推測しようとせずに、モダンな構文を受け入れます。
ファイルシステムチェックは、パーセントトークンまたは環境変数を含むパスをスキップします。それらの最終的な値は接続コンテキストに依存するためです。`LOCAL_COMMAND_DISABLED` も同様に保守的です。未解決の `Include` または可能性のある `PermitLocalCommand yes` がコマンドを有効にする可能性がある場合は抑制されます。最も正確な結果を得るには、通常の CLI または保存されたエディタドキュメントを通じて Include を解決してください。
## 開発
Rust 1.85 以降が必要です。
```bash
cargo test --all
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt -- --check
```
[CONTRIBUTING.md](https://github.com/noah4ever/sshconfig-lint/blob/main/CONTRIBUTING.md)、公開 [ロードマップ](https://github.com/noah4ever/sshconfig-lint/blob/main/ROADMAP.md)、
[v1 安定性契約](https://github.com/noah4ever/sshconfig-lint/blob/main/STABILITY.md)、[セキュリティポリシー](https://github.com/noah4ever/sshconfig-lint/blob/main/SECURITY.md)を参照してください。
## ライセンス
MIT