问题重现:
1. 首先在mac的ssh命令行中,使用ssh-keygen生成rsa密钥,并且将公钥复制到目标服务器的/root/.ssh/authorized_keys文件中
2. 使用命令行 ssh root@host 免密登录没有问题
3. 接着使用sshj进行ssh连接
String hostname ="1.1.1.1";
SSHClient client = new SSHClient();
client.addHostKeyVerifier(new PromiscuousVerifier());
client.loadKnownHosts();
//logger.debug("connect to "+hostname+" port:"+port);
client.setConnectTimeout(1000);
client.connect(hostname);
client.authPublickey("root");
4. 此时,authpublickey方法报出的root cause错误如下
.........
.........Exhausted available authentication methods
.......
net.schmizz.sshj.common.Buffer.readString Bad item length
......
5. 改用jsch进行ssh连接,代码如下
JSch jsch &