You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用PowerShell Posh-SSH时出现Permission denied (keyboard-interactive)错误

问题分析与解决步骤

1. 修正OpenSSH配置文件的错误操作

你修改的sshd_config_default是默认模板文件,实际生效的是同目录下的sshd_config文件:

  • 停止OpenSSH服务:Stop-Service sshd
  • 备份现有sshd_config后,将sshd_config_default复制为sshd_config
  • 编辑sshd_config,将PasswordAuthentication明确设置为no(不要仅注释原配置),同时确保KeyboardInteractiveAuthentication设为no
  • 重启服务:Start-Service sshd

2. 规范凭证变量的使用

两种调用方式的核心差异是凭证对象的初始化时机:

  • 方法A是即时生成新鲜的PSCredential对象传递,而方法B如果复用旧会话的变量,重启PowerShell后可能出现对象属性异常
  • 解决:每次新开PowerShell会话时,必须重新执行$cred = Get-Credential生成凭证,再传入New-SSHSession
  • 若需持久化凭证,用加密方式保存:
    # 保存凭证(仅当前用户可解密)
    $cred | Export-Clixml -Path "C:\temp\ssh_cred.xml"
    # 加载凭证
    $cred = Import-Clixml -Path "C:\temp\ssh_cred.xml"
    

3. 更新Posh-SSH模块

旧版本模块可能存在参数传递bug:

Update-Module -Name Posh-SSH -Force

若更新后问题依旧,可回退到稳定版本(示例版本可按需调整):

Install-Module -Name Posh-SSH -RequiredVersion 2.3.0 -Force

4. 查看OpenSSH日志定位根因

打开事件查看器,导航到应用程序和服务日志 > OpenSSH > Operational,查找ID为40的认证失败事件,查看详细错误信息确认拒绝原因。


内容的提问来源于stack exchange,提问作者user21974114

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 09:27:19