Class JSchUtils


  • public class JSchUtils
    extends Object
    Helper class for SSH connections using JSch.
    Author:
    FracPete (fracpete at waikato dot ac dot nz)
    • Constructor Detail

      • JSchUtils

        public JSchUtils()
    • Method Detail

      • newJsch

        public static com.jcraft.jsch.JSch newJsch​(File knownHosts)
                                            throws Exception
        Instantiates a new JSch object.
        Parameters:
        knownHosts - the file pointing to the known hosts config file, can be null
        Returns:
        the object
        Throws:
        Exception - if known hosts file fails
      • newSession

        public static com.jcraft.jsch.Session newSession​(com.jcraft.jsch.JSch jsch,
                                                         String user,
                                                         String password,
                                                         String host,
                                                         int port)
                                                  throws Exception
        Creates a new session using credentials-based authentication.
        Parameters:
        jsch - the JSch context
        user - the user
        password - the password to use
        host - the host to connect to
        port - the port to connect to
        Returns:
        the session
        Throws:
        Exception - if creation of session fails
      • newSession

        public static com.jcraft.jsch.Session newSession​(com.jcraft.jsch.JSch jsch,
                                                         String user,
                                                         File privateKey,
                                                         String password,
                                                         String host,
                                                         int port)
                                                  throws Exception
        Creates a new session using public-key-based authentication.
        Parameters:
        jsch - the JSch context
        user - the user
        privateKey - the private key file
        password - the password to use to open the private key file, empty or null if not necessary
        host - the host to connect to
        port - the port to connect to
        Returns:
        the session
        Throws:
        Exception - if creation of session fails
      • configureStrictHostKeyChecking

        public static void configureStrictHostKeyChecking​(com.jcraft.jsch.Session session,
                                                          boolean strict)
        Configures the session for strict host key checks.
        Parameters:
        session - the session to configure
        strict - true if to perform strict checks
      • configureX11

        public static void configureX11​(com.jcraft.jsch.Session session,
                                        String host,
                                        int port)
        Configures the session for X11.
        Parameters:
        session - the session to configure
        host - the X11 host
        port - the X11 port
      • getTechnicalInformation

        public static TechnicalInformation getTechnicalInformation()
        Returns an instance of a TechnicalInformation object, containing detailed information about the technical background of this class, e.g., paper reference or book this class is based on.
        Returns:
        the technical information about this class