Linux(bash):如何列出本地主机可用的SSH身份验证方法?

7

有没有一种使用命令行列出本地主机上所有可用的SSH身份验证方法的方法?基本上,我想要看到与从(远程)客户端尝试连接时服务器将宣布的相同列表。

注意:我不想搜索/ etc / ssh / sshd_config ,因为这需要太多理解存在哪些身份验证方法(例如,sshd_config可能为空)。


也许可以使用一些调试或详细输出参数连接到服务器? - Atle
我该如何在Linux命令行中实现这个? - mstrap
3个回答

9

使用ssh -v server命令并查找第一行“Authentications that can continue”。


1
谢谢!我从没想过会有这么简单的解决方案。 - mstrap

7

这里有一种更好的方法,源自这里,并由我修改以适应本地主机情况:

ssh -o PreferredAuthentications=none -o NoHostAuthenticationForLocalhost=yes localhost

5

nmap也可以使用ssh-auth-methods来实现此功能:

nmap -p 22 --script ssh-auth-methods localhost

示例输出:

Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-16 12:07 +07
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000087s latency).

PORT   STATE SERVICE
22/tcp open  ssh
| ssh-auth-methods: 
|   Supported authentication methods: 
|     publickey
|_    password

Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds

它在幕后所做的工作可以在ssh-auth-methods.nse中找到。使用libssh2随机连接用户名并列出可能的身份验证方法。

(有可能通过sshd -T打印出有效的sshd配置选项,即使sshd_config为空也会显示生效的选项。对于这种情况,运行sshd -T | egrep 'permitrootlogin|authentication'将会很有用。)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接