如何配置 yocto 以便任何人都不能在 yocto 映像中以 root 身份登录
How to configure yocto so that no one should be able to login as root in yocto image
我正在构建一个 yocto 映像,我不希望任何人都可以在其中以 root 身份登录。我不想删除该帐户,但这是我想要完成的。
我想禁用终端和 ssh 的根帐户访问权限,或者创建一个永远不会验证的密码。
我想让所有文件成为 root 所有者并将它们设置为 700 权限。
将这些行添加到您的图像配方中。
inherit extrausers
EXTRA_USERS_PARAMS = "usermod -L -e 1 root; "
这会锁定密码并使帐户过期。确保您的 IMAGE_FEATURES.
中没有 debug-tweaks
或 empty-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.
已检查:
- 无法使用 ssh 登录,即使在
/etc/ssh/sshd_config
中设置了 PermitRootLogin yes
$ su - root
是不可能的,即使 /etc/passwd
中的登录 shell 仍然指向 /bin/bash
而不是 /sbin/nologin
- 无法通过 root 登录到 ftp 服务器
未选中:
- 我没有检查如果我们将
systemd.unit=rescue.target
或 systemd.unit=emergency.target
添加到内核命令行会发生什么。
- ... ?
我正在构建一个 yocto 映像,我不希望任何人都可以在其中以 root 身份登录。我不想删除该帐户,但这是我想要完成的。 我想禁用终端和 ssh 的根帐户访问权限,或者创建一个永远不会验证的密码。 我想让所有文件成为 root 所有者并将它们设置为 700 权限。
将这些行添加到您的图像配方中。
inherit extrausers
EXTRA_USERS_PARAMS = "usermod -L -e 1 root; "
这会锁定密码并使帐户过期。确保您的 IMAGE_FEATURES.
中没有debug-tweaks
或 empty-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.
已检查:
- 无法使用 ssh 登录,即使在
/etc/ssh/sshd_config
中设置了 $ su - root
是不可能的,即使/etc/passwd
中的登录 shell 仍然指向/bin/bash
而不是/sbin/nologin
- 无法通过 root 登录到 ftp 服务器
PermitRootLogin yes
未选中:
- 我没有检查如果我们将
systemd.unit=rescue.target
或systemd.unit=emergency.target
添加到内核命令行会发生什么。 - ... ?