Ubuntu 云版本如何通过 ssh 强制执行“无 root 登录”?

Ubuntu 云版本如何通过 ssh 强制执行“无 root 登录”?

我正在寻找调整 ubuntu 云版本默认设置的方法,其中拒绝 root 登录。

尝试连接这样的机器会产生以下结果:

maxim@maxim-desktop:~/workspace/integration/deployengine$ ssh [email protected]
The authenticity of host 'ec2-204-236-252-95.compute-1.amazonaws.com (204.236.252.95)' can't be established.
RSA key fingerprint is 3f:96:f4:b3:b9:4b:4f:21:5f:00:38:2a:bb:41:19:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-204-236-252-95.compute-1.amazonaws.com' (RSA) to the list of known hosts.
Please login as the ubuntu user rather than root user.

Connection to ec2-204-236-252-95.compute-1.amazonaws.com closed.

我想知道在哪个配置文件中配置了通过 ssh 进行根阻止以及如何更改打印的消息?

答案1

老问题了,但是没有人真正回答你和我曾经有过同样的问题:这个配置从何而来?

它起源于cloudinit,恰恰cc_ssh.py/usr/lib/python2.7/dist-packages/cloudinit/config

这反过来又直接取决于文件/etc/cloud/cloud.cfg。你找到一行disable_root: true

您应该能够通过调整用户数据并添加行来覆盖它disable_root: false。您的云提供商应该使用户数据可配置。

答案2

假设您的 sshd 配置有PermitRootLogin yes

sudo grep "login as the ubuntu user" /root/.??*

然而,我强烈建议您仔细阅读并留意 Mike Scott 提供的链接。

根 SSH

最后,如果您希望绕过 Ubuntu 安全标准并恢复允许以 root 身份使用 ssh 和 rsync 的旧做法,则此命令将打开官方 Ubuntu 映像的新实例:

ssh -i KEYPAIR.pem ubuntu@HOSTNAME 'sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/' 我们不推荐这样做,但它可能是让现有 EC2 自动化代码继续工作的一种方法,直到您可以升级到上面描述的 sudo 实践。

我保持 root SSH 登录处于禁用状态,因为任何启用了 SSH 的面向公众的服务器都将日夜不断受到来自犯罪僵尸网络的 root 登录尝试的攻击。

文档在其他地方警告

启用 Root 帐户很少是必要的。作为 Ubuntu 系统管理员,您需要做的几乎所有事情都可以通过 sudo 或 gksudo 完成。如果您确实需要持久的 Root 登录,最好的选择是使用以下命令模拟 Root 登录 shell...

sudo -i

答案3

答案就在这里:http://alestic.com/2009/04/ubuntu-ec2-sudo-ssh-rsync

将 authorized_keys 文件从 ubuntu 帐户复制到 root 帐户。密码登录已禁用,因此您必须拥有有效的 ssh 密钥才能登录任何帐户。

答案4

检查 /etc/ssh/sshd_config,选项名为“允许 root 登录”

 PermitRootLogin
         Specifies whether root can log in using ssh(1).  The argument
         must be “yes”, “without-password”, “forced-commands-only”, or
         “no”.

更有用的设置之一是“无密码”,它允许您以 root 身份登录,但前提是您使用公钥身份验证。man sshd_config 了解更多信息:)

相关内容