简体   繁体   English

如何配置 yocto 以使任何人都不能在 yocto 映像中以 root 身份登录

[英]How to configure yocto so that no one should be able to login as root in yocto image

I am building a yocto image and I do not want anyone being able to login as root in it.我正在构建一个 yocto 映像,我不希望任何人能够以 root 身份登录。 I do not wish to remove the account but here is what I want to accomplish.我不想删除该帐户,但这是我想要完成的。 I want to disable root account access from terminal as well as ssh or create a password that will never validate.我想从终端以及 ssh 禁用 root 帐户访问,或者创建一个永远不会验证的密码。 I want to make all files root owner and set them to 700 permissions.我想让所有文件成为 root 所有者并将它们设置为 700 权限。

Add these lines to your image recipe.将这些行添加到您的图像配方中。

inherit extrausers

EXTRA_USERS_PARAMS = "usermod -L -e 1 root; "

This locks the password and expires the account.这会锁定密码并使帐户过期。 Make sure you don't have debug-tweaks or empty-root-password in your IMAGE_FEATURES.确保您的 IMAGE_FEATURES 中没有debug-tweaksempty-root-password

$ man usermod
   ...
   -e, --expiredate EXPIRE_DATE
       The date on which the user account will be disabled. The date is
       specified in the format YYYY-MM-DD.

       An empty EXPIRE_DATE argument will disable the expiration of the
       account.

       This option requires a /etc/shadow file. A /etc/shadow entry will
       be created if there were none.
   ...
   -L, --lock
       Lock a user's password. This puts a '!' in front of the encrypted
       password, effectively disabling the password. You can't use this
       option with -p or -U.

       Note: if you wish to lock the account (not only access with a
       password), you should also set the EXPIRE_DATE to 1.

Checked:检查:

  • Login with ssh is not possible, even though PermitRootLogin yes is set in /etc/ssh/sshd_config无法使用 ssh 登录,即使在/etc/ssh/sshd_config中设置了PermitRootLogin yes
  • $ su - root is not possible, even though the login shell in /etc/passwd still points to /bin/bash instead of /sbin/nologin $ su - root是不可能的,即使/etc/passwd中的登录 shell 仍然指向/bin/bash而不是/sbin/nologin
  • Login to ftp server via root is not possible无法通过 root 登录到 ftp 服务器

Not Checked:未检查:

  • I did not check what happens if we add systemd.unit=rescue.target or systemd.unit=emergency.target to the kernel commandline.如果我们将systemd.unit=rescue.targetsystemd.unit=emergency.target添加到 kernel 命令行,我没有检查会发生什么。
  • ... ? ... ?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM