Skip to content

feat: Add SSH configuration file parsing (-F option) #23

@inureyes

Description

@inureyes

Overview

Implement SSH configuration file parsing to support standard OpenSSH config format (~/.ssh/config), enabling bssh to read and apply SSH settings from config files with the -F option.

Technical Approach

Build a custom SSH config parser that:

  • Parses standard SSH config format with pattern matching
  • Integrates seamlessly with existing bssh configuration
  • Maintains precedence (CLI > SSH config > bssh config > defaults)
  • Supports wildcards and Include directives
  • Incremental implementation starting with core options

Implementation Tasks

Phase 1: Parser Foundation

  • Create SSH config parser module (src/ssh_config/mod.rs)
  • Implement tokenizer for SSH config format
  • Create data structures for config representation
  • Add basic parsing for Host blocks
  • Implement error handling with line numbers

Phase 2: Core SSH Options

  • Parse and apply Host/HostName options
  • Support Port, User, IdentityFile options
  • Implement StrictHostKeyChecking parsing
  • Add UserKnownHostsFile support
  • Handle IdentitiesOnly option

Phase 3: Pattern Matching

  • Implement wildcard pattern matching (* and ?)
  • Support Include directive for modular configs
  • Add first-match-wins semantics
  • Handle Host block inheritance

Phase 4: Advanced Options

  • Parse ProxyJump/ProxyCommand options
  • Support ConnectTimeout and timeouts
  • Implement ServerAliveInterval/CountMax
  • Add Compression and cipher preferences
  • Parse PreferredAuthentications

Phase 5: Integration

  • Integrate parser with CLI argument processing
  • Merge SSH config with bssh configuration
  • Apply configuration precedence rules
  • Add config validation and warnings

Priority Options to Support

Priority 1 (Must Have):

  • Host, HostName, Port, User
  • IdentityFile, StrictHostKeyChecking
  • UserKnownHostsFile

Priority 2 (Should Have):

  • ProxyJump, ProxyCommand
  • ConnectTimeout, ServerAliveInterval
  • Compression, PreferredAuthentications

Priority 3 (Nice to Have):

  • Match blocks, CanonicalizeHostname
  • LocalCommand, SendEnv

Success Criteria

  • Parse standard SSH configs without errors
  • Correctly resolve host patterns with wildcards
  • Apply options with proper precedence
  • Parse 1000-line config in < 10ms
  • Clear warnings for unsupported options
  • Full backward compatibility maintained

Examples

# Use specific SSH config
bssh -F ~/.ssh/config myhost

# Config example that should work:
Host bastion
    HostName bastion.example.com
    User admin
    Port 2222

Host internal-*
    ProxyJump bastion
    User deploy
    IdentityFile ~/.ssh/internal_key

# Usage:
bssh -F ~/.ssh/config internal-server

Labels

enhancement, help wanted, ssh-compat

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions