问题描述
通过 java 远程执行命令获取 ESXi 服务器的 thumbprint 字符串时报密码授权失败错误,错误信息如下:
java.io.IOException: Password authentication failed.
at ch.ethz.ssh2.auth.AuthenticationManager.authenticatePassword(AuthenticationManager.java:300)
at ch.ethz.ssh2.Connection.authenticateWithPassword(Connection.java:309)
at test.demo.TestSSH.main(TestSSH.java:19)
Caused by: java.io.IOException: Authentication method password not supported by the server at this stage.
at ch.ethz.ssh2.auth.AuthenticationManager.authenticatePassword(AuthenticationManager.java:270)
问题原因
ESXi 服务器(内核为 linux)的 ssh 服务中的 PasswordAuthentication 默认是不可用的,而且需确保允许 root 用户登录。
解决方法
所以只需要将 ssh 服务中的 PasswordAuthentication 启用即可,启用方法如下:
1、修改 sshd_config 文件,命令为:vi /etc/ssh/sshd_config ;
2、将 #PasswordAuthentication no 的注释#去掉,并且将 no 修改为 yes;
3、将 #PermitRootLogin yes 的注释#去掉,一般默认是打开的;
4、重新启动 SSH 服务,命令为:/etc/init.d/SSH restart ;
SSH login disabled
SSH login enabled
5、验证 SSH 服务状态,命令为:/etc/init.d/SSH status;
SSH login is started
参考:
如何开启ssh服务