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

Azure创建的Linux实例使用用户名密码SSH登录失败求助

解决方案

针对你遇到的Azure Linux实例SSH登录Permission denied(publickey)问题,结合已尝试的操作,可按以下步骤排查解决:

  • 检查testuser账户的SSH密钥与权限配置

    1. 通过Azure门户的串行控制台登录实例(无需SSH),操作testuser相关目录:
      • 确保~testuser/.ssh目录权限为700:chmod 700 ~testuser/.ssh
      • 确保~testuser/.ssh/authorized_keys文件权限为600:chmod 600 ~testuser/.ssh/authorized_keys
      • 确认authorized_keys内的公钥与你本地客户端的公钥(如id_rsa.pub)完全一致;若计划用密码登录,需给testuser设置密码:passwd testuser
  • 检查sshd_config的关键配置项

    1. 打开/etc/ssh/sshd_config,确认以下配置:
      • PubkeyAuthentication yes(若需保留密钥登录,默认开启)
      • PasswordAuthentication yes(确保未被注释)
      • ChallengeResponseAuthentication no
      • UsePAM yes
      • 无DenyUsers testuser规则,若有AllowUsers需包含testuser
    2. 验证配置语法正确性:sshd -t,无报错后重启服务:systemctl restart sshd
  • 排查网络层面限制

    1. 检查Azure网络安全组(NSG):确认入站规则允许22端口从你的客户端IP访问
    2. 检查实例本地防火墙:
      • 若用ufw:执行ufw allow ssh,再ufw reload
      • 若用firewalld:执行firewall-cmd --add-service=ssh --permanent,再firewall-cmd --reload
  • 检查SELinux与账户状态

    1. 临时关闭SELinux验证:setenforce 0,尝试重新SSH连接;若成功,修复目录上下文:restorecon -Rv ~testuser/.ssh
    2. 检查testuser是否被锁定:passwd -S testuser,若输出含L,执行passwd -u testuser解锁
    3. 确认testuser的shell有效:查看/etc/passwd中testuser行的最后一列,需为/bin/bash或其他可登录shell,而非/sbin/nologin
  • 强制密码登录测试
    若优先用密码登录,执行命令时强制指定认证方式:

    ssh -o PreferredAuthentications=password testuser@<IP address>
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 17:55:16