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


8

我想调整ubuntu云版本默认设置,其中拒绝root登录。

尝试连接到这样的机器会产生:

maxim@maxim-desktop:~/workspace/integration/deployengine$ ssh root@ec2-204-236-252-95.compute-1.amazonaws.com
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进行的根阻止配置以及如何更改打印的消息?

Answers:


14

这是个老问题,但没有人真正回答您,我也有同样的问题:此配置来自何处?

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

这又直接取决于文件/etc/cloud/cloud.cfg。你找到一条线disable_root: true

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


9
cloud-init所做的是/root/.ssh/authorized_keys在形式中 添加一行 no-port-forwarding,no-agent-forwarding,no-X11-forwarding,command="echo 'Please login as the user \"ubuntu\" rather than the user \"root\".';echo;sleep 10" ssh-rsa xxxxxx。因此,即使PermitRootLogin yesssh命令将无法获得有效的shell。
RubenLaguna 2015年

5

假设您的sshd配置具有PermitRootLogin yes

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

但是,麦克·斯科特提供的链接是我强烈建议您仔细阅读并留意的链接。

根SSH

最后,如果您希望绕开Ubuntu安全标准并恢复到以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


1
谢谢。cat /root/.ssh/authorized_keys包含一个打开echo而不是bash shell的通知。无法想象为什么我自己找不到它。谢谢。
Maxim Veksler 2010年


0

检查/ 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”.

更为有用的设置之一是“ without -password”,它使您可以在root用户上登录,但前提是您使用公共密钥身份验证。man sshd_config获取更多信息:)


ssh证书仅在所有EC2 linux实例上启用了身份验证,这是获得对计算机的远程访问的唯一方法。显然,我能够登录到该节点,否则上述消息将不会打印。另请注意:cat / etc / ssh / sshd_config | grep -i root PermitRootLogin yes
Maxim Veksler 2010年
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.