是否可以不通过密码和复制公钥进行 SSH root 登录?

是否可以不通过密码和复制公钥进行 SSH root 登录?

我想配置 sshd_config 以允许远程 root 登录而不提示输入密码,但我不想通过复制远程公钥来配置无密码 ssh。换句话说,我想允许从任何地方 ssh root@host 而不提示输入密码。这可以实现吗?

谢谢!

更多信息:

/etc/ssh/sshd_config

PermitEmptyPasswords yes
PubkeyAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
# passwd --delete root
# service ssh restart
sh@sh-desktop:~$ su - root
Password: 
su: Authentication failure

sh@sh-desktop:~$ ssh -vvv root@localhost
OpenSSH_6.6.1, OpenSSL 1.0.1f 6 Jan 2014
...
debug1: Authentications that can continue: publickey,password
Permission denied, please try again.

我也尝试过设置 UsePAM no,但我根本无法登录。也许需要在 PAM 配置中做点什么。

答案1

为了能够root通过以管理员身份登录ssh,您需要调整 SSH-Daemon 的配置 ( /etc/ssh/sshd_config)。

PermitEmptyPasswords yes
PermitRootLogin yes

要激活配置更改,您可以用以下命令重新启动守护程序:

systemctl restart ssh

这仅在用户root没有密码时才有效。您可以使用以下命令删除 root 的密码:

passwd --delete root

sudo编辑1:如果您尚未以 身份登录,则需要在这些命令前加上root

编辑2:所有这些更改都只需要在服务器端进行,无需在客户端进行任何更改。

答案2

事实证明,除了 sshd_config 中提到的参数之外,还需要以下内容。

编辑 /etc/pam.d/common-auth 将 nullok_secure 更改为 nullok

auth    [success=1 default=ignore]  pam_unix.so nullok

例如:

Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-27-generic x86_64)

$ ssh [email protected]
[email protected]'s password: 
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-27-generic x86_64)


ssh [email protected]
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 4.2.0-27-generic x86_64)

含义nullok_secure记录在旧版本的 pam_unix 手册页。 在Ubuntu 22该选项nullok_secure已被删除。

相关内容