ssh登录出现Permission denied, please try again可能的解决方案

这篇具有很好参考价值的文章主要介绍了ssh登录出现Permission denied, please try again可能的解决方案。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

问题描述

  • 环境:ubuntu 20.04
  • 问题描述:在已经设置免密登录后,ssh登录时(例如ssh localhost)还需要输入密码,并且输入密码后出现下面一系列的报错:
xxx(用户名)@localhost's password: 
Permission denied, please try again.
xxx@localhost's password: 
Permission denied, please try again.
xxx@localhost's password: 
xxx@localhost: Permission denied (publickey,password).

问题排查

首先使用命令ssh localhost -v查看登录时的日志:

OpenSSH_8.2p1 Ubuntu-4ubuntu0.5, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /home/yhy/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug1: Connecting to localhost [127.0.0.1] port 22.
debug1: Connection established.
debug1: identity file /home/yhy/.ssh/id_rsa type 0
debug1: identity file /home/yhy/.ssh/id_rsa-cert type -1
debug1: identity file /home/yhy/.ssh/id_dsa type 1
debug1: identity file /home/yhy/.ssh/id_dsa-cert type -1
debug1: identity file /home/yhy/.ssh/id_ecdsa type -1
debug1: identity file /home/yhy/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/yhy/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/yhy/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/yhy/.ssh/id_ed25519 type -1
debug1: identity file /home/yhy/.ssh/id_ed25519-cert type -1
debug1: identity file /home/yhy/.ssh/id_ed25519_sk type -1
debug1: identity file /home/yhy/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/yhy/.ssh/id_xmss type -1
debug1: identity file /home/yhy/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
debug1: match: OpenSSH_8.2p1 Ubuntu-4ubuntu0.5 pat OpenSSH* compat 0x04000000
debug1: Authenticating to localhost:22 as 'yhy'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ssh-ed25519 SHA256:KgNVsJSzDmK9KHR57LTY2Xarsui27l0FIm9CY2fUO6o
debug1: Host 'localhost' is known and matches the ED25519 host key.
debug1: Found key in /home/yhy/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/yhy/.ssh/id_dsa DSA SHA256:G/HRSEJY5SzAo4ejVp+GVHkIp+UjzMTETklcP2P0ym4 agent
debug1: Will attempt key: /home/yhy/.ssh/id_rsa RSA SHA256:ysy/bD0PakYR49V2kxCs95GxfpHjLifTAPqNJ5yH480 agent
debug1: Will attempt key: /home/yhy/.ssh/id_ecdsa 
debug1: Will attempt key: /home/yhy/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/yhy/.ssh/id_ed25519 
debug1: Will attempt key: /home/yhy/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/yhy/.ssh/id_xmss 
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,sk-ssh-ed25519@openssh.com,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256@openssh.com>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering public key: /home/yhy/.ssh/id_dsa DSA SHA256:G/HRSEJY5SzAo4ejVp+GVHkIp+UjzMTETklcP2P0ym4 agent
debug1: Authentications that can continue: publickey,password
debug1: Offering public key: /home/yhy/.ssh/id_rsa RSA SHA256:ysy/bD0PakYR49V2kxCs95GxfpHjLifTAPqNJ5yH480 agent
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/yhy/.ssh/id_ecdsa
debug1: Trying private key: /home/yhy/.ssh/id_ecdsa_sk
debug1: Trying private key: /home/yhy/.ssh/id_ed25519
debug1: Trying private key: /home/yhy/.ssh/id_ed25519_sk
debug1: Trying private key: /home/yhy/.ssh/id_xmss
debug1: Next authentication method: password

从日志上看,应该还是配置的问题。

可能的原因

  • 配置问题:如果是ssh配置的问题首先可以尝试这里修改配置。(如果之前从未修改过相关配置,大概率不是这里的问题)
    进行上面的方法后,如果还不行,说明不是配置文件的问题。
  • 文件权限问题:有时文件权限也可能会导致登录失败,按照上述方法查看日志后,如果日志中出现有关文件权限的错误badownership,那么就要考虑.ssh文件夹和authorized_keys文件的权限问题了。
    进入.ssh文件夹下,使用如下命令查看文件夹的信息:
    ll -ld
    
    drwx------ 3 xxx xxx 4096 53 08:41 ./
    
    该目录必须具有上面所示的读(r)、写(w)、执行(x) 权限,如果没有则需要使用命令:
    chmod 0700 /home/your_home/.ssh
    
    修改权限;
    使用命令:
    /home/xxx/.ssh$ ls -ld authorized_keys
    
    -rw------- 1 yhy yhy 564 53 07:08 authorized_keys
    
    查看文件authorized_keys的文件权限。该文件必须有上面所示的读写(rw) 权限,否则使用命令:
    chmod 0600 /home/[username]/.ssh/authorized_keys
    
    修改权限。
  • zsh问题:如果上述方法都不奏效,且你正在/曾经使用zsh那么恭喜你可能遇到了和我相同的问题。这个问题可以通过命令
    service sshd status
    
    查看ssh服务运行状态发现,如果运行日志中有:
    User xxx not allowed because shell /bin/zsh
    
    那么就是由于zsh使用问题导致。我的问题是之前使用过 zsh,卸载后忘记修改默认终端,导致ssh出现问题。
    首先查看系统可用终端:
$ cat /etc/shells

# /etc/shells: valid login shells
/bin/sh
/bin/bash
/usr/bin/bash
/bin/rbash
/usr/bin/rbash
/bin/dash
/usr/bin/dash
/bin/zsh
/usr/bin/zsh

可以看到由于之前设置过该文件,所以里面有bin/zshusr/bin/zsh,如果zsh已经卸载的话,可以删除后面这两行。
通过命令sudo nautilus可以以管理员身份打开文件夹,并且任意对里面的文件进行修改。
接下来查看系统默认shell

$ echo $SHELL
/bin/zsh

可以看到还是因为之前的设置,默认shellzsh。通过命令:

grep xxx(你的用户名) /etc/passwd #这条命令显示/etc/passwd中用户的终端设置

sudo chsh --shell /bin/bash xxx #这条命令修改用户的默认终端为/bin/bash

grep xxx /etc/passwd #再次查看,默认终端已经变成/bin/bash

在用户登录时,系统会根据/etc/passwd中的设置为用户设置默认终端,所以执行完上述操作后重启,再次检查默认终端:

echo $SHELL
/bin/bash

会发现终端已经改成了/bin/bash
这时候再试一试ssh localhost,会发现登录成功:
ssh登录出现Permission denied, please try again可能的解决方案
问题得到解决。

如果上面的方法都不能解决,就要根据日志和服务状态信息中的其它内容进行排查了。

总结

这个ssh登录失败问题困扰了我很长时间,试了网上很多种方法都没有奏效,最后查看系统服务日志才发现问题所在。以后删除某个软件的时候,一定要把相关的配置还原成为默认的,否则不知道哪天会出问题!文章来源地址https://www.toymoban.com/news/detail-489784.html

到了这里,关于ssh登录出现Permission denied, please try again可能的解决方案的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 用户ssh正确密码登陆树莓派镜像均报错Permission denied, please try again.处理方法

    一个树莓派镜像,启动后发现没有 sshd 功能,于是 启用 openssh,重新启动,又发现树莓派拒绝 ssh 连接请求。 我的一台树莓派IP是:192.168.59.133任何服务器使用任何用户ssh均报错,甚至连自己都不能ssh自己。 不能使用任何工具连接上该服务器 使用ssh连接自己的127.0.0.1和localh

    2024年01月22日
    浏览(36)
  • Git解决Permission denied, please try again问题

    在gitlab上传项目的时候出现Permission denied, please try again问题。 在使用git克隆或上传项目的时候出现 git@xxx password: 让你输入密码,你发现无论输入什么都会出现Permission denied, please try again问题,其实这个主要是工程的SSH key没有加入到你的gitlab账户下。 在git中输入cd ~/.ssh/ 回车

    2024年02月10日
    浏览(35)
  • Git 解决 Permission denied, please try again 问题

    git pull 在上传项目的时候出现 git@xxx password: 让你输入密码,你发现无论输入什么都会出现Permission denied, please try again问题,其实这个主要是工程的SSH key没有加入到你的gitlab账户下 1、检查SSH Key存在 如果存在id_rsa.pub 或 id_dsa.pub 文件,跳过此步。 2、创建SSH Key 创建ssh key时会提

    2024年02月15日
    浏览(41)
  • git报错:git Permission denied, please try again.

    git clone/pull代码时提示输入密码,密码输入正确但是报错: git Permission denied, please try again. step1 检查SSH Key是否存在 step2 获取SSH Key 如果存在id_rsa.pub 或 id_dsa.pub 文件,跳过此步。 如果不存在,则生成: 先查看git邮箱地址 再生成SSH Key step3 将公钥复制到git页面profile setting SSHK

    2024年02月05日
    浏览(40)
  • windows配置openssh,以及密码正确时Permission denied, please try again

    最近在搭建jenkins 环境管理项目 需要用到ssh。而服务器目前只有一台windows可以使用..... 首先去到官网去下载,至于我为什么去官网下载.....因为遇到了部分问题,win10里面就可以直接下载   但是我从官网下载安装到了e盘,因为opensshsshd.config文件用win10安装的话是只读不可修改

    2023年04月20日
    浏览(24)
  • github 配置了公钥依旧提示git@github.com‘s password: Permission denied, please try again

    在github上添加密钥后 输出如下 在 HTTPS 端口使用 SSH 有时,防火墙会完全拒绝允许 SSH 连接。 如果无法选择使用具有凭据缓存的 HTTPS 克隆,可以尝试使用通过 HTTPS 端口建立的 SSH 连接克隆。 大多数防火墙规则应允许此操作,但代理服务器可能会干扰 如果这样有效,万事大吉

    2024年02月15日
    浏览(64)
  • !!!已解决: Linux操作系统登录,输入正确账号密码显示却显示:Sorry, that didn‘t work. Please try again.

    先给大家复现一下我的问题: 为什么出现这个问题??? 后来我找到了原因: 解决方案: 【补充:】 下面展示一些 内联代码片 。

    2024年02月12日
    浏览(37)
  • Read timed out Please check your internet connection and try again

    java 对接 stripe 海外支付,报错信息如下 IOException during API request to Stripe (https://api.stripe.com): Read timed out Please check your internet connection and try again. If this problem persists,you should check Stripe\\\'s service status at https://twitter.com/stripestatus, or let us know at support@stripe.com. 这个错误通常表示 API 请

    2023年04月11日
    浏览(26)
  • Pycharm 安装 github copilot 报错:failed to initiate the github login process please try again

    下载安装好copilot插件后,提示failed to initiate the github login process please try again 就非常的emo。。。     我的pycharm是2021.1版本,在setting中安装最新版copilot1.1.35.2063(我这两个版本亲测可使用) 之前有教程说,可以去copilot官网降低copilot版本,解决这个报错问题。但是,若降低版

    2024年02月02日
    浏览(36)
  • 已解决Error: A JNI error has occurred, please check your installation and try again

    已解决Error: A JNI error has occurred, please check your installation and try again Error: A JNI error has occurred, please check your installation and try again 这个错误通常表示Java Native Interface (JNI)的安装出现了问题。 下滑查看解决方法 以下是解决该错误的一些可能方法: 检查Java环境变量:确保正确设置了

    2024年02月06日
    浏览(62)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包