private static void loadIdentity(SecureShell sch, FileInfo priv)
 {
     if (!priv.IsFile()) return;
     try
     {
         sch.AddIdentity(priv.FullName);
     }
     catch (Exception)
     {
         // Instead, pretend the key doesn't exist.
     }
 }
 private static void identities(SecureShell sch)
 {
     DirectoryInfo home = FS.userHome();
     if (home == null)
         return;
     var sshdir = PathUtil.CombineDirectoryPath(home, ".ssh");
     if (sshdir.IsDirectory())
     {
         loadIdentity(sch, PathUtil.CombineFilePath(sshdir, "identity"));
         loadIdentity(sch, PathUtil.CombineFilePath(sshdir, "id_rsa"));
         loadIdentity(sch, PathUtil.CombineFilePath(sshdir, "id_dsa"));
     }
 }
 private static void knownHosts(SecureShell sch)
 {
     DirectoryInfo home = FS.userHome();
     if (home == null)
         return;
     var known_hosts = new FileInfo(Path.Combine(home.ToString(), ".ssh/known_hosts"));
     try
     {
         using (var s = new StreamReader(known_hosts.FullName))
         {
             sch.SetKnownHosts(s);
         }
     }
     catch (FileNotFoundException)
     {
         // Oh well. They don't have a known hosts in home.
     }
     catch (IOException)
     {
         // Oh well. They don't have a known hosts in home.
     }
 }
 /// <summary>
 /// Returns the new default JSch implementation
 /// </summary>
 /// <returns>the new default JSch implementation</returns>
 protected static SecureShell createDefaultJSch()
 {
     SecureShell jsch = new SecureShell();
     knownHosts(jsch);
     identities(jsch);
     return jsch;
 }
 private SecureShell getDefaultJSch()
 {
     if (_defaultSecureShell == null)
     {
         _defaultSecureShell = createDefaultJSch();
         foreach (object name in _defaultSecureShell.getIdentityNames())
         {
             _byIdentityFile.put((string)name, _defaultSecureShell);
         }
     }
     return _defaultSecureShell;
 }
        /// <summary>
        /// Obtain the JSch used to create new sessions.
        /// </summary>
        /// <param name="hc">host configuration</param>
        /// <returns>the JSch instance to use.</returns>
        protected SecureShell getJSch(OpenSshConfig.Host hc)
        {
            if (hc == null)
                throw new System.ArgumentNullException("hc");

            SecureShell def = getDefaultJSch();
            FileInfo identityFile = hc.getIdentityFile();
            if (identityFile == null)
                return def;

            string identityKey = identityFile.FullName;
            SecureShell jsch = _byIdentityFile[identityKey];
            if (jsch == null)
            {
                jsch = new SecureShell();
                jsch.SetHostKeyRepository(def.GetHostKeyRepository());
                jsch.AddIdentity(identityKey);
                _byIdentityFile.Add(identityKey, jsch);
            }
            return jsch;
        }