@Override protected void configure(OpenSshConfig.Host hc, Session session) { if (!GitMonitoringService.this.strictHostKeyCheckingEnabled) { session.setConfig("StrictHostKeyChecking", "no"); } }
@Override protected void configure(Host hc, Session session) { session.setConfig("StrictHostKeyChecking", isStrictHostKeyChecking() ? "yes" : "no"); } });
@Override protected void configure(OpenSshConfig.Host hc, Session session) { session.setConfig("StrictHostKeyChecking", sshUriProperties.isStrictHostKeyChecking() ? "yes" : "no"); } });
private Session newJSchSession() throws JSchException { JSch jsch = new JSch(); if (identityPath != null) { jsch.addIdentity(identityPath); } Session session = jsch.getSession(username, hostname, port); if (password != null) { session.setPassword(password); } session.setConfig("StrictHostKeyChecking", "no"); return session; }
@Override protected void configure(Host hc, Session session) { JGitEnvironmentProperties sshProperties = sshKeysByHostname.get(hc.getHostName()); String hostKeyAlgorithm = sshProperties.getHostKeyAlgorithm(); if (hostKeyAlgorithm != null) { session.setConfig(SERVER_HOST_KEY, hostKeyAlgorithm); } if (sshProperties.getHostKey() == null || !sshProperties.isStrictHostKeyChecking()) { session.setConfig(STRICT_HOST_KEY_CHECKING, NO_OPTION); } else { session.setConfig(STRICT_HOST_KEY_CHECKING, YES_OPTION); } String preferredAuthentications = sshProperties.getPreferredAuthentications(); if (preferredAuthentications != null) { session.setConfig(PREFERRED_AUTHENTICATIONS, preferredAuthentications); } }
private Session createSession(String host, Args args) throws JSchException { JSch jsch = new JSch(); for (String keyFile : getKeyFiles()) { jsch.addIdentity(keyFile); } JSch.setLogger(new LogAdapter()); Session session = jsch.getSession(args.user, host, args.sshPort); session.setConfig("StrictHostKeyChecking", "no"); return session; }
Session session = jsch.getSession(user, host, port); session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); System.out.println("Establishing Connection..."); session.connect();
public void login( String password ) throws KettleJobException { this.password = password; s.setPassword( this.getPassword() ); try { java.util.Properties config = new java.util.Properties(); config.put( "StrictHostKeyChecking", "no" ); // set compression property // zlib, none String compress = getCompression(); if ( compress != null ) { config.put( COMPRESSION_S2C, compress ); config.put( COMPRESSION_C2S, compress ); } s.setConfig( config ); s.connect(); Channel channel = s.openChannel( "sftp" ); channel.connect(); c = (ChannelSftp) channel; } catch ( JSchException e ) { throw new KettleJobException( e ); } }
session.setConfig("StrictHostKeyChecking", "no"); session.connect();
Session session = jsch.getSession(user, host, 22); session.setPassword(password); session.setConfig("StrictHostKeyChecking", "no"); session.connect();
session.setConfig("StrictHostKeyChecking", "no"); session.connect();
/** * 打开一个新的SSH跳板机会话 * * @param sshHost 跳板机主机 * @param sshPort 跳板机端口 * @param sshUser 跳板机用户名 * @param sshPass 跳板机密码 * @return SSH会话 */ public static Session openSession(String sshHost, int sshPort, String sshUser, String sshPass) { if (StrUtil.isEmpty(sshHost) || sshPort < 0 || StrUtil.isEmpty(sshUser) || StrUtil.isEmpty(sshPass)) { return null; } Session session; try { session = new JSch().getSession(sshUser, sshHost, sshPort); session.setPassword(sshPass); //设置第一次登陆的时候提示,可选值:(ask | yes | no) session.setConfig("StrictHostKeyChecking", "no"); session.connect(); } catch (JSchException e) { throw new JschRuntimeException(e); } return session; }
private void setSession() { JSch ssh; // wait until SSH port of remote end comes up boolean success = waitActive( SESSION_CONNECT_TIMEOUT ); if( ! success ) { LOG.warn( "Port 22 of {} did not open in time", value.getPublicIpAddress() ); } // try to open ssh session try { Thread.sleep( 30000 ); ssh = new JSch(); ssh.addIdentity( value.getSshKeyFile() ); session = ssh.getSession( Utils.DEFAULT_USER, value.getPublicIpAddress() ); session.setConfig( "StrictHostKeyChecking", "no" ); session.connect(); } catch ( Exception e ) { LOG.error( "Error while connecting to ssh session of " + value.getPublicIpAddress(), e ); session = null; } }
public static Session createSession(final SFTPConfiguration conf, final JSch jsch) throws JSchException, IOException { if (conf == null || null == jsch) { throw new NullPointerException(); } final Hashtable<String, String> newOptions = new Hashtable<>(); Session session = jsch.getSession(conf.username, conf.hostname, conf.port); final String hostKeyVal = conf.hostkeyFile; if (null != hostKeyVal) { try { jsch.setKnownHosts(hostKeyVal); } catch (final IndexOutOfBoundsException iob) { throw new IOException("Unable to establish connection due to bad known hosts key file " + hostKeyVal, iob); } } else { newOptions.put("StrictHostKeyChecking", "no"); session.setConfig(newOptions); } final String privateKeyVal = conf.privatekeyFile; if (null != privateKeyVal) { jsch.addIdentity(privateKeyVal, conf.privateKeypassphrase); } if (null != conf.password) { session.setPassword(conf.password); } session.setTimeout(conf.connectionTimeout); //set timeout for connection session.connect(); session.setTimeout(conf.dataTimeout); //set timeout for data transfer return session; }
/** * Given SFTP connection configuration, and -Duserauth.gssapi.enabled param was NOT passed on application start. * <br/> * When SFTP Client is instantiated, then preferred authentications list should not contain * GSS API Authentication. */ @Test public void shouldExcludeGssapiFromPreferredAuthenticationsByDefault() throws Exception { new SFTPClient( server, port, username ) { @Override JSch createJSch() { return jSch; } }; verify( session ) .setConfig( "PreferredAuthentications", "publickey,keyboard-interactive,password" ); }
session.setConfig("StrictHostKeyChecking", "no"); session.connect();
/** * 打开一个新的SSH跳板机会话 * * @param sshHost 跳板机主机 * @param sshPort 跳板机端口 * @param sshUser 跳板机用户名 * @param sshPass 跳板机密码 * @return SSH会话 */ public static Session openSession(String sshHost, int sshPort, String sshUser, String sshPass) { if (StrUtil.isEmpty(sshHost) || sshPort < 0 || StrUtil.isEmpty(sshUser) || StrUtil.isEmpty(sshPass)) { return null; } Session session; try { session = new JSch().getSession(sshUser, sshHost, sshPort); session.setPassword(sshPass); //设置第一次登陆的时候提示,可选值:(ask | yes | no) session.setConfig("StrictHostKeyChecking", "no"); session.connect(); } catch (JSchException e) { throw new JschRuntimeException(e); } return session; }
/** * Given SFTP connection configuration, and -Duserauth.gssapi.enabled param * was passed on application start with correct value. * <br/> * When SFTP Client is instantiated, then preferred authentications list should contain * GSS API Authentication as the last one. */ @Test public void shouldIncludeGssapiToPreferredAuthenticationsIfSpecified() throws Exception { System.setProperty( SFTPClient.ENV_PARAM_USERAUTH_GSSAPI, "true" ); new SFTPClient( server, port, username ) { @Override JSch createJSch() { return jSch; } }; verify( session ) .setConfig( "PreferredAuthentications", "publickey,keyboard-interactive,password,gssapi-with-mic" ); }
/** * Given SFTP connection configuration, and -Duserauth.gssapi.enabled param * was passed on application start with incorrect value. * <br/> * When SFTP Client is instantiated, then preferred authentications list should not contain * GSS API Authentication. */ @Test public void shouldIncludeGssapiToPreferredAuthenticationsIfOnlySpecifiedCorrectly() throws Exception { System.setProperty( SFTPClient.ENV_PARAM_USERAUTH_GSSAPI, "yes" ); new SFTPClient( server, port, username ) { @Override JSch createJSch() { return jSch; } }; verify( session ) .setConfig( "PreferredAuthentications", "publickey,keyboard-interactive,password" ); }
s.setConfig( PREFERRED_AUTH_CONFIG_NAME, getPreferredAuthentications() ); } catch ( IOException e ) { throw new KettleJobException( e );