本文整理了Java中com.jcraft.jsch.JSch.setConfig()
方法的一些代码示例,展示了JSch.setConfig()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSch.setConfig()
方法的具体详情如下:
包路径:com.jcraft.jsch.JSch
类名称:JSch
方法名:setConfig
[英]Sets a default configuration option. This option is used by all sessions, if for these sessions was not set a specific value for this key with Session#setConfig.
Here is the list of configuration options used by the program. They all have sensible default values (use the source if you want to know the defaults).
These options contain a (comma-separated, without spaces) list of algorithms, which will be offered to the server, and from which one will be selected by negotiation during key exchange. These should confirm to the format defined by RFC 4250, and be accompanied by an "implementation" option.
kexKey exchange algorithms server_host_key Algorithms supported for the server host key. cipher.s2cencryption algorithms used for server-to-client transport. See CheckCiphers. cipher.c2sencryption algorithms used for client-to-server transport. See CheckCiphers. mac.c2smessage authentication code algorithms for client-to-server transport. mac.s2cmessage authentication code algorithms for server-to-client transport. compression.c2sCompression algorithms for client-to-server transport. The default is "none", but this library also supports "zlib" and "zlib@openssh.com". (Other compression algorithms can't be put in, it seems.) compression.s2cCompression algorithms for server-to-client transport. The default is "none", but this library also supports "zlib" and "zlib@openssh.com". (Other compression algorithms can't be put in, it seems.) lang.s2cLanguage preferences for server-to-client human readable messages (should normally be empty) lang.c2sLanguage preferences for client-to-server human readable messages (should normally be empty)
During key exchange, the first option in the client's list (i.e. the option value) which also appears on the server's list will be choosen for each algorithm. Thus the order matters here.
The following options contain the class name of classes implementing a specific algorithm. They should implement the interface or abstract class mentioned here.
The classes must be findable using the class loader which loaded the JSch library (e.g. by a simple Class#forName inside the library classes), and must have a no-argument constructor, which will be called to instantiate the objects needed. Then the actual interface methods will be used.
diffie-hellman-group-exchange-sha1 Diffie-Hellman Key Exchange with a group chosen by the server (RFC 4419). diffie-hellman-group1-sha1 Diffie-Hellman key exchange with a fixed group. (RFC 4253, section 7)
ecdh-sha2-nistp Elliptic curve Diffie Hellmann key exchange. (RFC 5656, section 4)
(The mentioned ones have implementations included in the library, of course you can add more, adding them to cipher.s2cand/or cipher.c2s. The RFC mentioned is the RFC which defined the keywords, here with links: RFC 4253, SSH Transport Layer Protocol, Section 6.3 Encryption, RFC 4344, SSH Transport Layer Encryption Modes (which defines the CTR mode for most of the ciphers of RFC 4253), and RFC 4345, Improved Arcfour Modes for SSH.)
3des-cbcthree-key 3DES in CBC mode (RFC 4253) 3des-ctr blowfish-cbcBlowfish in CBC mode (RFC 4253) aes256-cbcAES in CBC mode, with a 256-bit key (RFC 4253) aes192-cbcAES with a 192-bit key (RFC 4253) aes128-cbcAES with a 128-bit key (RFC 4253) aes128-ctrAES (Rijndael) in SDCTR mode, with 128-bit key (RFC 4344) aes192-ctrAES with 192-bit key (RFC 4344) aes256-ctrAES with 256-bit key (RFC 4344) arcfourthe ARCFOUR stream cipher with a 128-bit key (RFC 4253) arcfour128a variant of the ARCFOUR cipher (still with 128-bit key), which discards the first 1536 bytes of keystream before encryption will begin. (RFC 4345) arcfour256Like arcfour128, but with a 256-bit key. (RFC 4345). noneThe null cipher (i.e. no encryption) (RFC 4345, RFC 2410)
These keywords are defined in RFC 4253, section 6.4 Data Integrity. The basic HMAC algorithm is defined in RFC 2104.
hmac-sha1HMAC-SHA1 (digest length = key length = 20) hmac-sha1-96first 96 bits of HMAC-SHA1 (digest length = 12, key length = 20) hmac-md5HMAC-MD5 (digest length = key length = 16) hmac-md5-96first 96 bits of HMAC-MD5 (digest length = 12, key length = 16)
(It is now hardcoded that only these two (and none) are actually accepted, even if providing more ones with compression.s2c or compression.c2s. I think the reason is the special handling necessary for zlib@openssh.com.)
zlibzlib compression as defined by RFC 1950+1951 zlib@openssh.com A variant of the zlib compression where the compression only starts after the client user is authenticated. This is described in the Internet-Draft draft-miller-secsh-compression-delayed-00.
Here the user sends a list of methods, and we have a list of methods in the option PreferredAuthentications (in preference order). We take the first of our methods which is supported by the server, get the userauth.method variable to load the implementing class, and try to authenticate. This will repeat until we are authenticated or no more methods left.
The following ones are built in:
userauth.none mainly for getting the list of methods the server supports. userauth.password usual password authentication. userauth.keyboard-interactive Using the generic message exchange authentication mechanism, as defined in RFC 4256. userauth.publickey public key authentication, using an Identity. userauth.gssapi-with-mic Using the GSS-API (see below) as defined in RFC 4462, section 3.
For the GSS-API mechanism we need an implementation of GSSContext to refer to, which will be chosen by the configuration option gssapi-with-mic.method, the method being chosen from a list given by the server. For now, we (hardcoded) only support the krb5 method, resulting in:
gssapi-with-mic.krb5Kerberos 5 authentication.
The following options do not correspond to algorithm names as defined in the SSH protocols, but are used to implement the underlying cryptographic functions.
dh DH - Diffie-Hellman mathematics. random Random - random number generation. signature.dss SignatureDSA signature.rsa SignatureRSA signature.ecdsa SignatureECDSA keypairgen.dsa KeyPairGenDSA keypairgen.rsa KeyPairGenRSA pbkdf PBKDF - password based key generation, using PKDF 2 with HMAC-SHA1
And the cryptographic hash algorithms ( HASH):
sha-1The Secure Hash Algorithm, version 1. md5The Message Digest 5 algorithm.
Here are options not fitting in any of the other categories.
compression_levelThe compression level for client-to-server transport. This will only be used if the negotiated compression method is one of zlib and zlib@openssh.com (other methods are not supported anyway). PreferredAuthenticationsA preference order of our preferred authentication methods. Each of them should have a corresponding userauth.method configuration option defining the implementation class. StrictHostKeyCheckingIndicates what to do if the server's host key changed or the server is unknown. One of yes (refuse connection), ask (ask the user whether to add/change the key) and no (always insert the new key). HashKnownHostsIf this is "yes" and we are using the default known-hosts file implementation, new added server keys will be hashed. CheckCiphersA list of Ciphers which should be first checked for availability. All ciphers in this list which are not working will be removed from the ciphers.c2s and ciphers.s2c before sending these lists to the server in a KEX_INIT message.
[中]设置默认配置选项。如果未使用Session#setConfig为这些会话设置此键的特定值,则所有会话都会使用此选项。
以下是程序使用的配置选项列表。它们都有合理的默认值(如果您想知道默认值,请使用源代码)。
####算法列表
这些选项包含一个(逗号分隔,不带空格)算法列表,将提供给服务器,并在密钥交换期间通过协商从中选择一个算法。这些应符合RFC 4250定义的格式,并附有“实施”选项。
kexKey交换算法服务器主机密钥支持的服务器主机密钥算法。密码用于服务器到客户端传输的S2C加密算法。见CheckCiphers。密码用于客户端到服务器传输的C2S加密算法。见CheckCiphers。雨衣。用于客户端到服务器传输的C2S消息身份验证代码算法。雨衣。用于服务器到客户端传输的s2cmessage身份验证代码算法。压缩。用于客户端到服务器传输的C2S压缩算法。默认值为“无”,但此库还支持“zlib”和zlib@openssh.com“(其他压缩算法似乎无法加入。)压缩。服务器到客户端传输的S2C压缩算法。默认值为“无”,但此库还支持“zlib”和zlib@openssh.com“(其他压缩算法似乎无法加入。)服务器到客户端人类可读消息的lang.s2clan语言首选项(通常应为空)客户端到服务器人类可读消息的lang.c2slan语言首选项(通常应为空)
在密钥交换期间,将为每个算法选择客户端列表中的第一个选项(即选项值),该选项也出现在服务器列表中。因此,这里的顺序很重要。
####实现类
以下选项包含实现特定算法的类的类名。它们应该实现这里提到的接口或抽象类。
必须使用加载JSch库的类加载器(例如,通过库类中的简单类#forName)查找类,并且必须具有无参数构造函数,该构造函数将被调用以实例化所需的对象。然后将使用实际的接口方法。
#####密钥交换算法(密钥交换)
diffie-hellman-group-exchange-sha1与服务器选择的组(RFC 4419)进行diffie-hellman密钥交换。diffie-hellman-group1-sha1与固定组进行diffie-hellman密钥交换。(RFC 4253, section 7)
#####椭圆曲线密钥交换算法(ECDH)
ecdh-sha2-nistp椭圆曲线Diffie-Hellmann密钥交换。(RFC 5656, section 4)
#####对称加密算法(密码)
(上面提到的实现包含在库中,当然您可以添加更多,将它们添加到cipher.s2cnd/or cipher.c2s。上面提到的RFC是定义关键字的RFC,这里有链接:RFC 4253, SSH Transport Layer Protocol, Section 6.3 Encryption、{$6$}(为RFC4253的大多数密码定义CTR模式)和{$7$}。)
CBC模式下的3des CBC三键3des(RFC 4253)CBC模式下的3des ctr河豚cbcBlowfish(RFC 4253)CBC模式下的aes256 cbcAES,带256位密钥(RFC 4253)aes192 cbcAES和192位密钥(RFC 4253)aes128 cbcAES和128位密钥(RFC 4253)aes128 ctrAES(Rijndael)SDCTR模式下,使用128位密钥(RFC 4344)aes192 ctrAES with 192位密钥(RFC 4344)aes256 ctrAES with 256位密钥(RFC 4344)ARCFOUR使用128位密钥(RFC 4253)的ARCFOUR流密码ARCFOUR 128A是ARCFOUR密码(仍然使用128位密钥)的变体,它在加密开始之前丢弃密钥流的前1536字节。(RFC 4345)arcfour256Like arcfour128,但具有256位密钥。(RFC 4345)。无空密码(即无加密)(RFC 4345,RFC 2410)
#####消息认证码算法(MAC)
这些关键字在RFC 4253, section 6.4 Data Integrity中定义。基本HMAC算法在RFC 2104中定义。
hmac-sha1HMAC-SHA1(摘要长度=密钥长度=20)hmac-SHA1-96 hmac-SHA1的前96位(摘要长度=12,密钥长度=20)hmac-md5HMAC-MD5(摘要长度=密钥长度=16)hmac-MD5-96 hmac-MD5的前96位(摘要长度=12,密钥长度=16)
#####压缩方法(压缩)
(现在硬编码的是,实际上只接受这两个(并且没有),即使提供更多的压缩。s2c或压缩。c2s。我认为这是因为我们需要特殊的处理zlib@openssh.com.)
RFC 1950+1951定义的zlibzlib压缩zlib@openssh.comzlib压缩的一种变体,其中压缩仅在客户端用户经过身份验证后开始。因特网草案{{10$}对此作了说明。
#####用户身份验证方法(UserAuth)
在这里,用户发送一个方法列表,我们在选项PreferredAuthentications中有一个方法列表(按优先顺序)。我们采用服务器支持的第一种方法,即获取userauth。方法变量来加载实现类,并尝试进行身份验证。这将重复进行,直到我们通过身份验证或没有其他方法。
以下是内置的:
userauth。无主要用于获取服务器支持的方法列表。userauth。密码-通常的密码身份验证。userauth。使用RFC 4256中定义的通用消息交换身份验证机制进行键盘交互。userauth。公钥公钥身份验证,使用标识。userauth。gssapi与mic使用RFC 4462, section 3中定义的GSS-API(见下文)。
对于GSS-API机制,我们需要参考GSSContext的实现,该实现将由配置选项gssapi with mic选择。方法,该方法从服务器提供的列表中选择。目前,我们(硬编码)仅支持krb5方法,导致:
带麦克风的gssapi。krb55认证。
#####杂项算法
以下选项与SSH协议中定义的算法名称不对应,但用于实现底层加密功能。
dh-Diffie-Hellman数学。随机-随机数生成。签名dss签名SA签名。rsa签名者签名。ecdsa签名CDSA keypairgen。dsa KeyPairGenDSA Keypairgend。rsa KeyPairGenRSA pbkdf pbkdf-使用PKDF 2和HMAC-SHA1生成基于密码的密钥
以及加密哈希算法(哈希):
sha-1安全哈希算法,版本1。MD5消息摘要5算法。
####其他选择
以下是不适用于任何其他类别的选项。
压缩级别客户端到服务器传输的压缩级别。仅当协商压缩方法是zlib和zlib@openssh.com(无论如何都不支持其他方法)。PreferredAuthentications是我们的preferred authentication methods的优先顺序。它们中的每一个都应该有一个相应的userauth。定义实现类的方法配置选项。StrictHostKeyChecking指示在服务器的主机密钥更改或服务器未知时要执行的操作。是(拒绝连接)、询问(询问用户是否添加/更改密钥)和否(始终插入新密钥)之一。HashKnownHostsIf为“是”,并且我们使用默认的已知主机文件实现,新添加的服务器密钥将被散列。checkciphers首先检查可用性的密码列表。此列表中所有不起作用的密码将从密码中删除。c2s和密码。s2c,然后在KEX_INIT消息中将这些列表发送到服务器。
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Create default instance of jsch
*
* @param fs
* the file system abstraction which will be necessary to perform
* certain file system operations.
* @return the new default JSch implementation.
* @throws com.jcraft.jsch.JSchException
* known host keys cannot be loaded.
*/
protected JSch createDefaultJSch(FS fs) throws JSchException {
final JSch jsch = new JSch();
JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa")); //$NON-NLS-1$ //$NON-NLS-2$
JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss")); //$NON-NLS-1$ //$NON-NLS-2$
configureJSch(jsch);
knownHosts(jsch, fs);
identities(jsch, fs);
return jsch;
}
代码示例来源:origin: net.sf.sshapi/sshapi-jsch
private void checkConfig(String cipher, String name, String key) {
checkFirstConnection();
String[] split = JSch.getConfig(key).split(",");
List ciphers = new ArrayList(Arrays.asList(split));
ciphers.remove(cipher);
ciphers.add(0, cipher);
String delimited = Util.toDelimited((String[]) ciphers.toArray(new String[ciphers.size()]), ',');
JSch.setConfig(key, delimited);
}
代码示例来源:origin: apache/oozie
@Override
protected JSch createDefaultJSch(final FS fs) throws JSchException {
JSch.setConfig("StrictHostKeyChecking", "no");
final JSch defaultJSch = super.createDefaultJSch(fs);
if (credentialFile != null) {
defaultJSch.addIdentity(credentialFile.toString());
}
return defaultJSch;
}
};
代码示例来源:origin: io.vertx/vertx-config-git
@Override
protected JSch createDefaultJSch(FS fs ) throws JSchException {
JSch defaultJSch = super.createDefaultJSch( fs );
defaultJSch.setConfig("StrictHostKeyChecking", "no");
defaultJSch.addIdentity(configuration.getString("idRsaKeyPath"));
return defaultJSch;
}
};
代码示例来源:origin: vert-x3/vertx-config
@Override
protected JSch createDefaultJSch(FS fs ) throws JSchException {
JSch defaultJSch = super.createDefaultJSch( fs );
defaultJSch.setConfig("StrictHostKeyChecking", "no");
defaultJSch.addIdentity(configuration.getString("idRsaKeyPath"));
return defaultJSch;
}
};
代码示例来源:origin: org.apache.camel/camel-jsch
protected void initJsch() {
JSch.setConfig("StrictHostKeyChecking", "yes");
JSch.setLogger(new com.jcraft.jsch.Logger() {
@Override
public boolean isEnabled(int level) {
return level == FATAL || level == ERROR ? LOG.isErrorEnabled()
: level == WARN ? LOG.isWarnEnabled()
: level == INFO ? LOG.isInfoEnabled() : LOG.isDebugEnabled();
}
@Override
public void log(int level, String message) {
if (level == FATAL || level == ERROR) {
LOG.error("[JSCH] {}", message);
} else if (level == WARN) {
LOG.warn("[JSCH] {}", message);
} else if (level == INFO) {
// JSCH is verbose at INFO logging so allow to turn the noise down and log at DEBUG by default
if (isVerboseLogging()) {
LOG.info("[JSCH] {}", message);
} else {
LOG.debug("[JSCH] {}", message);
}
} else {
LOG.debug("[JSCH] {}", message);
}
}
});
}
代码示例来源:origin: stackoverflow.com
JSch jsch = new JSch();
JSch session = null;
try {
String command="grep 'keyword1' filename.txt|grep -v 'keyword2'";
session = jsch.getSession(userid, servername, serverport);
session.setPassword(password);
session.setConfig("StrictHostKeyChecking", "no");
session.setConfig("PreferredAuthentications", "publickey,keyboard-interactive,password");
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand(command);
channel.connect();
InputStream commandOutput = channel.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(commandOutput));
while ((line = br.readLine()) != null)
{
System.out.println(line);
}
br.close();
channel.disconnect()
session.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
代码示例来源:origin: stackoverflow.com
JSch jsch = new JSch();
String path = "PATH TO PRIVATE KEY";
jsch.addIdentity(path);
jsch.setConfig("StrictHostKeyChecking", "no");
Session session = jsch.getSession(userName, ipToConnect, portToConnect);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand("COMMAND TO FIRE");
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
//Read Response Here
channel.disconnect();
session.disconnect();
代码示例来源:origin: stackoverflow.com
JSch jsch = new JSch();
String path = "PATH TO PRIVATE KEY";
jsch.addIdentity(path);
jsch.setConfig("StrictHostKeyChecking", "no");
Session session = jsch.getSession(userName, ipToConnect, portToConnect);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand("COMMAND TO FIRE");
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in = channel.getInputStream();
channel.connect();
//Read Response Here
channel.disconnect();
session.disconnect();
代码示例来源:origin: berlam/github-bucket
/**
* Create default instance of jsch
*
* @param fs
* the file system abstraction which will be necessary to perform
* certain file system operations.
* @return the new default JSch implementation.
* @throws com.jcraft.jsch.JSchException
* known host keys cannot be loaded.
*/
protected JSch createDefaultJSch(FS fs) throws JSchException {
final JSch jsch = new JSch();
JSch.setConfig("ssh-rsa", JSch.getConfig("signature.rsa")); //$NON-NLS-1$ //$NON-NLS-2$
JSch.setConfig("ssh-dss", JSch.getConfig("signature.dss")); //$NON-NLS-1$ //$NON-NLS-2$
configureJSch(jsch);
knownHosts(jsch, fs);
identities(jsch, fs);
return jsch;
}
代码示例来源:origin: org.ikasan/ikasan-test
public void putFile(String fileName, final String content) throws Exception
{
JSch jsch = new JSch();
Hashtable config = new Hashtable();
config.put("StrictHostKeyChecking", "no");
JSch.setConfig(config);
Session session = jsch.getSession(user, "localhost", sshd.getPort());
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.cd(baseDir);
sftpChannel.put(new ByteArrayInputStream(content.getBytes()), fileName);
if (sftpChannel.isConnected())
{
sftpChannel.exit();
}
if (session.isConnected())
{
session.disconnect();
}
filesToCleanup.add(FileSystems.getDefault().getPath(baseDir+FileSystems.getDefault().getSeparator()+fileName));
}
代码示例来源:origin: org.ikasan/ikasan-test
public InputStream getFile(String fileName) throws Exception
{
JSch jsch = new JSch();
Hashtable config = new Hashtable();
config.put("StrictHostKeyChecking", "no");
JSch.setConfig(config);
Session session = jsch.getSession(user, "localhost", sshd.getPort());
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.cd(baseDir);
InputStream inputStream = sftpChannel.get(fileName);
if (sftpChannel.isConnected())
{
sftpChannel.exit();
}
if (session.isConnected())
{
session.disconnect();
}
return inputStream;
}
代码示例来源:origin: com.amysta.jclouds.driver/jclouds-jsch
@Override
public Session create() throws Exception {
JSch jsch = new JSch();
session = jsch
.getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22));
if (sessionTimeout != 0)
session.setTimeout(sessionTimeout);
if (loginCredentials.hasUnencryptedPrivateKey()) {
byte[] privateKey = loginCredentials.getOptionalPrivateKey().get().getBytes();
jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
} else if (loginCredentials.getOptionalPassword().isPresent()) {
session.setPassword(loginCredentials.getOptionalPassword().orNull());
} else if (agentConnector.isPresent()) {
JSch.setConfig("PreferredAuthentications", "publickey");
jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get()));
}
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
if (proxy.isPresent())
session.setProxy(proxy.get());
session.connect(connectTimeout);
return session;
}
代码示例来源:origin: apache/jclouds
@Override
public Session create() throws Exception {
JSch jsch = new JSch();
session = jsch
.getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22));
if (sessionTimeout != 0)
session.setTimeout(sessionTimeout);
if (loginCredentials.hasUnencryptedPrivateKey()) {
byte[] privateKey = loginCredentials.getOptionalPrivateKey().get().getBytes();
jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
} else if (loginCredentials.getOptionalPassword().isPresent()) {
session.setPassword(loginCredentials.getOptionalPassword().orNull());
} else if (agentConnector.isPresent()) {
JSch.setConfig("PreferredAuthentications", "publickey");
jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get()));
}
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
if (proxy.isPresent())
session.setProxy(proxy.get());
session.connect(connectTimeout);
return session;
}
代码示例来源:origin: com.meltmedia.cadmium/cadmium-core
protected com.jcraft.jsch.JSch getJSch(OpenSshConfig.Host hc, FS fs)
throws com.jcraft.jsch.JSchException
{
JSch jsch = super.getJSch(hc, fs);
JSch.setConfig("StrictHostKeyChecking", "no");
if(FileSystemManager.exists(privateKeyFile)) {
jsch.addIdentity(privateKeyFile);
}
jsch.setKnownHosts(knownHostsFile);
return jsch;
}
代码示例来源:origin: alipay/rdf-file
/**
* 通过用户名和私钥认证,发起ssh连接。
*
* @param user FTP登录用户
* @return
* @throws JSchException
*/
private static Session connectByIdentity(SFTPUserInfo user) throws JSchException {
if(RdfFileUtil.isBlank(user.getIdentityFile())){
throw new RdfFileException("rdf-file#JschFactory.connectByPasswd私钥文件不能为空"
, RdfErrorEnum.ILLEGAL_ARGUMENT);
}
Properties sshConfig = new Properties();
sshConfig.put("StrictHostKeyChecking", "no");
JSch.setConfig(sshConfig);
JSch jsch = new JSch();
jsch.addIdentity(user.getIdentityFile());
Session sshSession = jsch.getSession(user.getUser(), user.getHost(), user.getPort());
return sshSession;
}
代码示例来源:origin: com.meltmedia.cadmium/cadmium-core
protected com.jcraft.jsch.JSch getJSch(OpenSshConfig.Host hc, FS fs)
throws com.jcraft.jsch.JSchException
{
JSch jsch = super.getJSch(hc, fs);
JSch.setConfig("StrictHostKeyChecking", "no");
if(FileSystemManager.exists(privateKeyFile)) {
jsch.addIdentity(privateKeyFile);
} else if (FileSystemManager.exists(sshDir + "/id_rsa")) {
jsch.addIdentity(sshDir + "/id_rsa");
}
jsch.setKnownHosts(knownHostsFile);
return jsch;
}
代码示例来源:origin: com.jcabi/jcabi-ssh
JSch.setConfig("StrictHostKeyChecking", "no");
JSch.setLogger(new JschLogger());
final JSch jsch = new JSch();
代码示例来源:origin: alipay/rdf-file
sshConfig.put("StrictHostKeyChecking", user.getStrictHostKeyChecking());
JSch.setConfig(sshConfig);
JSch jsch = new JSch();
代码示例来源:origin: omegat-org/omegat
@Override
protected JSch createDefaultJSch(FS fs) throws JSchException {
Connector con = null;
try {
if (SSHAgentConnector.isConnectorAvailable()) {
USocketFactory usf = new JNAUSocketFactory();
con = new SSHAgentConnector(usf);
} else {
ConnectorFactory cf = ConnectorFactory.getDefault();
con = cf.createConnector();
}
} catch (AgentProxyException e) {
Log.log(e);
}
JSch jsch = super.createDefaultJSch(fs);
if (con != null) {
JSch.setConfig("PreferredAuthentications", "publickey");
IdentityRepository irepo = new RemoteIdentityRepository(con);
jsch.setIdentityRepository(irepo);
}
return jsch;
}
};
内容来源于网络,如有侵权,请联系作者删除!