Class OpenSshConfig

java.lang.Object
org.eclipse.jgit.transport.ssh.jsch.OpenSshConfig
All Implemented Interfaces:
com.jcraft.jsch.ConfigRepository

public class OpenSshConfig extends Object implements com.jcraft.jsch.ConfigRepository
Fairly complete configuration parser for the OpenSSH ~/.ssh/config file.

JSch does have its own config file parser OpenSSHConfig since version 0.1.50, but it has a number of problems:

  • it splits lines of the format "keyword = value" wrongly: you'd end up with the value "= value".
  • its "Host" keyword is not case insensitive.
  • it doesn't handle quoted values.
  • JSch's OpenSSHConfig doesn't monitor for config file changes.

This parser makes the critical options available to SshSessionFactory via OpenSshConfig.Host objects returned by lookup(String), and implements a fully conforming ConfigRepository providing ConfigRepository.Configs via getConfig(String).

Since:
6.0
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    Configuration of one "Host" block in the configuration file.

    Nested classes/interfaces inherited from interface com.jcraft.jsch.ConfigRepository

    com.jcraft.jsch.ConfigRepository.Config
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The base file.

    Fields inherited from interface com.jcraft.jsch.ConfigRepository

    defaultConfig, nullConfig
  • Constructor Summary

    Constructors
    Constructor
    Description
    Create an OpenSshConfig
  • Method Summary

    Modifier and Type
    Method
    Description
    get(FS fs)
    Obtain the user's configuration data.
    com.jcraft.jsch.ConfigRepository.Config
    getConfig(String hostName)
    lookup(String hostName)
    Locate the configuration for a specific host request.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Constructor Details

    • OpenSshConfig

      public OpenSshConfig(File h, File cfg)
      Create an OpenSshConfig
      Parameters:
      h - user's home directory
      cfg - ssh configuration file
  • Method Details

    • get

      public static OpenSshConfig get(FS fs)
      Obtain the user's configuration data.

      The configuration file is always returned to the caller, even if no file exists in the user's home directory at the time the call was made. Lookup requests are cached and are automatically updated if the user modifies the configuration file since the last time it was cached.

      Parameters:
      fs - the file system abstraction which will be necessary to perform certain file system operations.
      Returns:
      a caching reader of the user's configuration file.
    • lookup

      public OpenSshConfig.Host lookup(String hostName)
      Locate the configuration for a specific host request.
      Parameters:
      hostName - the name the user has supplied to the SSH tool. This may be a real host name, or it may just be a "Host" block in the configuration file.
      Returns:
      r configuration for the requested name. Never null.
    • getConfig

      public com.jcraft.jsch.ConfigRepository.Config getConfig(String hostName)

      Retrieves the full Config for the given host name. Should be called only by Jsch and tests.

      Specified by:
      getConfig in interface com.jcraft.jsch.ConfigRepository
      Since:
      4.9
    • toString

      public String toString()
      Overrides:
      toString in class Object