尝试登录 openssh,权限被拒绝

尝试登录 openssh,权限被拒绝

我一直尝试以 root 身份登录到 ubuntu 11.04 服务器上的 ssh,并将 AllowRootLogin 设置为是,但我收到了“权限被拒绝”的提示。这是我使用 ssh -v 尝试的副本:

Last login: Fri Jun  8 21:07:20 on ttys000
noah-sisks-macbook-pro:~ phreshness$ ssh -v [email protected] -p 22
OpenSSH_5.6p1, OpenSSL 0.9.8r 8 Feb 2011
debug1: Reading configuration data /etc/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.133 [192.168.1.133] port 22.
debug1: Connection established.
debug1: identity file /Users/phreshness/.ssh/id_rsa type -1
debug1: identity file /Users/phreshness/.ssh/id_rsa-cert type -1
debug1: identity file /Users/phreshness/.ssh/id_dsa type -1
debug1: identity file /Users/phreshness/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.9p1 Debian-5ubuntu1
debug1: match: OpenSSH_5.9p1 Debian-5ubuntu1 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.6
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.1.133' is known and matches the RSA host key.
debug1: Found key in /Users/phreshness/.ssh/known_hosts:6
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/phreshness/.ssh/id_rsa
debug1: Trying private key: /Users/phreshness/.ssh/id_dsa
debug1: Next authentication method: password
[email protected]'s password: 
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.
[email protected]'s password: 

答案1

您的服务器日志上输出的内容是什么?该消息通常在root未经授权的用户尝试登录时显示。例如,我使用以下行禁用了我的 root 登录/etc/ssh/sshd_config

PermitRootLogin 否

另一种可能性是您的服务器允许的用户列表有限,配置中的行是:

允许用户 用户1 用户2

还有一个DenyUsers。更多信息请见man sshd_config
当有人尝试像root我的服务器一样登录时,会/var/log/auth.log显示以下内容:

6月7日 19:45:05 jaguar sshd[26999]: 来自192.168.1.3 端口 10916 ssh2 的无效用户 root 的密码失败
6月7日 19:45:06 jaguar sshd[26999]: 连接由 192.168.1.3 [preauth] 关闭

客户端上的消息与您的类似:

$ ssh -l 根美洲虎
root@jaguar 的密码:
权限被拒绝,请重试。

您可以尝试使用调试运行服务器,并且不要分离这样的选项(需要可执行文件的完整路径):

/usr/sbin/sshd -D -d -p 22

要在同一个端口上启动新进程,您应该停止常规服务器,或使用不同的服务器来监听并连接到客户端。

答案2

PermitRootLogin在您的 SSH 配置中设置Yes不会覆盖不允许 root 登录的 Ubuntu 安全策略。

如果你想通过 SSH 以 root 身份登录,你需要先启用 root 账户(注意,你几乎从不需要以 root 身份登录,sudo对于需要 root 权限的任何任务来说,这几乎总是足够的。请参阅这里有关 Ubuntu 的 sudo 和 root 帐户的安全策略的更多信息)。

也就是说,如果您确实想通过 SSH 以 root 身份登录,请先通过设置密码来启用 root 帐户。

sudo passwd root

然后,假设PermitRootLogin您的 SSH 服务器配置中仍启用了,您应该能够通过 SSH 以 root 身份登录。请注意,您确实应该使用 Public/Private密钥对登录到 root 帐户,以防止启用 root 帐户并允许其通过 SSH 登录这一相当危险的业务变得彻底危险。

一旦您完成了使用 root 帐户需要执行的操作,我建议您通过删除密码再次禁用它。

sudo passwd -dl root

答案3

一个问题是,root 在默认系统中没有密码。一个常见的误解是,你在每个sudo命令后输入的密码是 root 的密码。实际上,你输入的密码是你自己

因此您需要做的只是为 root 添加一个密码:

sudo passwd root

然后您应该能够使用默认的 open-ssh 设置以 root 身份登录:

ssh [email protected]

相关内容