ssh异常登录问题处理记录


=Start=

缘由:

简单记录一下前段时间出现的ssh登录异常问题的处理办法,方便以后参考。

正文:

参考解答:

现象:ssh突然登录不上云机器了

$ ssh [email protected]
[email protected]: Permission denied (publickey,keyboard-interactive).

$ ssh -vv [email protected]

排查过程:

  1. 通过web控制台登录其它账号进行查看
systemctl status sshd
sshd -t
  1. 发现错误提示:
    error: Could not load host key: /etc/ssh/ssh_host_dsa_key

找到相关文章说明:

$ ls -al /etc/ssh/ssh*key 
$ sudo rm -r /etc/ssh/ssh*key

$ sudo systemctl restart sshd
# 或
$ sudo ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
$ sudo ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
$ sudo ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key 

$ ls -al /etc/ssh/ssh*key 
  1. 然后再尝试登录,依旧报错,不过换了一个错误提示:
    sshd user xxx not allowed because account is locked
  2. 又找到相关说明,进行尝试
# 更新 sshd 的配置文件
# vim /etc/ssh/sshd_config
+ UsePAM yes
# PasswordAuthentication yes 安装时一般也默认有这个配置,如果没了也需要加上

# systemctl restart sshd
# systemctl status sshd

或

# 直接修改 /etc/shadow 文件(这个办法暂未实际测试)
# sed -i s/my-username:!/"my-username:*"/g /etc/shadow

问题解决。

参考链接:

Linux有问必答:如何修复“sshd error: could not load host key”
https://linux.cn/article-4226-1.html

How to fix “sshd error: could not load host key”
https://www.xmodulo.com/sshd-error-could-not-load-host-key.html

User username not allowed because account is locked #35
https://github.com/camptocamp/puppet-accounts/issues/35

ssh免密失败,报错user not allowed because account is locked
https://www.cnblogs.com/mingfan/p/13818902.html

ssh报user not allowed because account is locked错误
https://blog.csdn.net/weixin_41875646/article/details/84777346

=END=

,

《 “ssh异常登录问题处理记录” 》 有 3 条评论

  1. 用scp进行文件传递时提示“subsystem request failed on channel 1”
    `
    添加 -O 选项解决了我的这个问题。

    try to use -O option with scp. This solved the same issue in my case with 9.0p1.
    It forces to use the legacy SCP protocol for file transfers instead of the SFTP protocol. Use of the SCP protocol may be necessary for servers that do not implement SFTP, for backwards-compatibility for particular filename wildcard patterns and for expanding paths with a ‘~’ prefix for older SFTP servers.
    `
    subsystem request failed on channel 0 scp: Connection closed – Macbook
    https://stackoverflow.com/questions/74311661/subsystem-request-failed-on-channel-0-scp-connection-closed-macbook

    subsystem request failed on channel 0,scp: connection closed
    https://github.com/PowerShell/Win32-OpenSSH/issues/1945

  2. 当时用scp命令进行文件传输时,如果提示“/usr/bin/scp 权限不够”,可能有几种原因:
    1. 源目录或目的目录的权限不够,需要给添加权限,或者临时放在/tmp目录下做中转;
    2. scp命令没有可执行权限(我在真实场景中遇到过,有些厂商把scp等命令的可执行权限给去掉了),sudo chmod加上权限就好;
    3. ssh命令出了问题,可以参考上面的内容进行处理和修复,修复好了再来看scp命令。

    permission denied while scp in linux
    https://juejin.cn/s/permission%20denied%20while%20scp%20in%20linux
    `

    在Linux中使用scp命令时,如果你遇到了”permission denied”的错误提示,可能是由于以下几个原因导致的:
    1. 文件或目录权限不足。请检查源文件或目录和目标目录的权限,确保你有足够的权限访问它们。可以使用ls -l命令来查看文件或目录的权限。
    2. 源文件或目录不存在。请确保你指定的源文件或目录确实存在,否则会出现”permission denied”错误。
    3. 目标目录不存在。如果你指定的目标目录不存在,scp命令会尝试创建它,但如果你没有足够的权限创建目录,则会出现”permission denied”错误。
    4. 防火墙或SELinux设置。如果你的Linux系统启用了防火墙或SELinux安全模块,可能会阻止scp命令进行传输。你可以尝试在防火墙或SELinux中打开相关端口或者禁用防火墙或SELinux来解决问题。

    以下是几个解决”permission denied”错误的方法:
    1. 检查文件或目录的权限,确保你有足够的权限访问它们。
    2. 确保源文件或目录存在,以及目标目录存在或可以创建。
    3. 禁用SELinux或防火墙,或者在防火墙或SELinux中打开相关端口。
    4. 在使用scp命令时加上-v选项,以便在命令输出中查看更详细的错误信息,以帮助你更好地排查问题。

    希望这些方法能够帮助你解决”permission denied”错误。如果还有其他问题,请随时提问。
    `

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注