Permission denied, please try again.

本文介绍了解决Linux CentOS 6.5系统中SCP命令出现权限拒绝错误的方法。通过对比正常服务器与故障服务器的配置文件/etc/pam.d/sshd,发现了多余的配置行导致特定用户无法通过SSH连接。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

linux centos6.5

当从一台机器执行scp的时候,报错:

Permission denied, please try again.

报错的消息是没有权限,密码应该是正确的,也可以得到验证。

那么怎么会没有权限呢?我用的不是root用户,并且root用户也应该是有权限的。

查看服务器端的日志文件/var/log/secure,当输入密码后,报错信息如下:

sshd[27915]: Connection closed by xxxxxxx
sshd[27939]: pam_listfile(sshd:auth): Refused user oracle for service sshd
sshd[27939]: Failed password for oracle from xxxxx port 63581 ssh2

关键的错误是: pam_listfile(sshd:auth): Refused user oracle for service sshd

查看文件/etc/pam.d/sshd 

这个东西没有研究过,也没有遇到过类似的错误,但是可以使用对比大发,找到一台正常的服务器,对比这两个文件


有错误的:

#%PAM-1.0
auth       required     pam_listfile.so item=user sense=allow file=/etc/sshusers-allowed onerr=fail
auth       required     pam_sepermit.so
auth       include      password-auth
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    required     pam_namespace.so
session    optional     pam_keyinit.so force revoke
session    include      password-auth


正常的:
#%PAM-1.0
auth       required     pam_sepermit.so
auth       include      password-auth
account    required     pam_nologin.so
account    include      password-auth
password   include      password-auth
# pam_selinux.so close should be the first session rule
session    required     pam_selinux.so close
session    required     pam_loginuid.so
# pam_selinux.so open should only be followed by sessions to be executed in the user context
session    required     pam_selinux.so open env_params
session    optional     pam_keyinit.so force revoke
session    include      password-auth


发现有错误的上面多了一行,注释掉这行,然后重启sshd服务试试:

# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]

好了。



上面/etc/sshusers-allowed文件的作用是只允许里面的用户连接ssh,是一种安全机制。


### SSH 连接中相关提示的翻译 在 SSH 连接过程中,可能会遇到以下两种常见的提示信息: #### 1. `Permission denied, please try again` 此提示的中文翻译为“权限被拒绝,请重试”。该错误通常表示客户端尝试登录目标主机时,提供的凭据无效或未被授权。可能的原因包括: - 用户名或密码错误。 - 服务器端未配置允许该客户端 IP 地址连接[^2]。 - SSH 密钥认证失败,例如私钥格式不正确或公钥未正确添加到服务器的 `~/.ssh/authorized_keys` 文件中[^3]。 示例场景: ```bash root@localhost's password: Permission denied, please try again. ``` #### 2. `The authenticity of host can't be established` 此提示的中文翻译为“无法验证主机的真实性”。当客户端首次连接到某个主机时,如果无法确认主机的公钥指纹,则会显示此提示。这是为了防止中间人攻击,确保连接的安全性[^2]。 示例场景: ```bash The authenticity of host '192.168.1.100 (192.168.1.100)' can't be established. ECDSA key fingerprint is SHA256:abcdef1234567890abcdef1234567890abcdef12. Are you sure you want to continue connecting (yes/no)? ``` --- ### 解决方案概述 对于 `Permission denied, please try again` 错误,可以采取以下措施: - 确保输入的用户名和密码正确。 - 检查服务器端是否启用了密码认证功能。如果仅允许密钥认证,则需要配置正确的 SSH 密钥对[^3]。 - 将客户端的 IP 地址添加到服务器端的 `/etc/ssh/sshd_config` 文件中以允许访问[^2]。 对于 `The authenticity of host can't be established` 提示,可以通过以下方式解决: - 手动验证主机的公钥指纹是否匹配,并输入 `yes` 继续连接。 - 使用 `-o StrictHostKeyChecking=no` 参数跳过主机密钥检查,但这会降低安全性[^2]。 --- ### 示例代码 #### 验证主机密钥指纹 在目标主机上运行以下命令获取其 ECDSA 密钥指纹: ```bash ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub ``` #### 跳过主机密钥检查 使用以下命令通过 SCP 或 SSH 连接时忽略主机密钥检查: ```bash scp -o StrictHostKeyChecking=no user@host:/path/to/file ./local/path ``` #### 添加 SSH 密钥到服务器 将本地公钥复制到远程服务器: ```bash ssh-copy-id user@remote_host ``` ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值