【问题标题】:How to add Sudouser in Yocto如何在 Yocto 中添加 Sudouser
【发布时间】:2020-08-15 15:16:12
【问题描述】:

我想在 Yocto 中添加一个新的 Sudouser。根密码适用于更改并添加了新用户,但它不是 Sudouser。如何添加 Sudouser?我读了很多谷歌文章并试图复制它们,但都失败了。我做了一个食谱,但它不起作用,只将它添加到 local.conf 是有效的。

  1. 添加额外用户。 (新用户:test1,密码:pass11!)
  2. 禁用 debug-tweaks 以更改 root 的密码。
  3. 更改根密码。 (无 --> pass1234!)

以下是我在local.conf中添加的代码。

# EXTRA_IMAGE_FEATURES = "debug-tweaks package-management"

INHERIT += "extrausers"
EXTRA_USERS_PARAMS = " usermod -P pass1234! root; \
                       useradd test1; \
                       usermod -P pass11! test1; "

如果有任何建议,我将不胜感激。

【问题讨论】:

  • 首先,拥有两个具有完全 root 权限的用户不会以任何方式提高安全性:您可能需要考虑您的计划(在评论中提到)是否有意义。其次,“sudouser”不是我熟悉的术语。如果您想使用 sudo 您首先需要将其添加到您的图像中(默认情况下不包含它,因为它通常在嵌入式上下文中没有多大意义)并对其进行配置,以便新用户获得所需的权限

标签: passwords sudo yocto recipe


【解决方案1】:

谢谢罗伯特。我从 Toradex 工程师那里找到了解决方案。

如果有人和我一样有问题,请尝试以下方法。

  1. 更改根密码。

在 local.conf 中添加以下内容。我没有使用我的食谱。

EXTRA_IMAGE_FEATURES=""
INHERIT += "extrausers"
EXTRA_USERS_PARAMS = " usermod -P password root; "

如果有人不能使用ssh,请参考here

  1. 添加具有root权限的新用户。
EXTRA_IMAGE_FEATURES=""
INHERIT += "extrausers"
EXTRA_USERS_PARAMS = " usermod -P password1 root; \
            useradd -ou 0 -g 0 newuser; \ 
            usermod -P password2 newuser; "

也许您的用户帐户无法使用“ifconfig”之类的命令,因为您的用户帐户没有路径“/sbin”。转到您的 Yocto 代码并找到正确的文件并为您的用户帐户添加 /sbin。

r@p:~/oe-core/layers$ grep -r /etc/profile .
./meta-toradex-demos/recipes-core/base-files/base-files/profile:# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
./meta-toradex-demos/recipes-core/base-files/base-files/profile:if [ -d /etc/profile.d ]; then
./meta-toradex-demos/recipes-core/base-files/base-files/profile:  for i in /etc/profile.d/* ; do
if [ "$HOME" = "/home/root" ]; then
   PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
fi

if [ "$HOME" = "/home/newuser" ]; then
   PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
fi

【讨论】:

    【解决方案2】:

    0) 您想在哪里进行更改?

    在某些配置文件中,如上,或例如在图像配方中 - 见下文。

    1) 你想给 root 一个密码?

    这可能会有所帮助:

    https://wiki.yoctoproject.org/wiki/FAQ:How_do_I_set_or_change_the_root_password

    2) 然后你想创建另一个用户是 sudoer 组的成员吗?

    意味着更多的用户将拥有 root 权限。

    为什么?

    【讨论】:

    • 嗨。感谢你的回复。 2)的答案是肯定的。我想给另一个用户root权限。我想更改配置文件,因为我在我的食谱中测试了新用户,但我无法成功。我的 root 帐户已经有密码。所以这没关系。我关心的是给新用户一个root权限。我的经理想添加另一个用户,但这个用户也有 root 权限,如 root 帐户。所以我必须添加自定义用户,如 root 帐户。如果您看到我的代码,test1 是新用户,但 test1 没有 root 权限。如果您知道如何授予 test1 的 root 权限,请告诉我。
    【解决方案3】:

    让我们进入第 2 部分)sudoers

    这是我在板上做的快速测试。你能尝试类似的东西并告诉我这是否是你想要的吗?确认后,我们将了解如何将其添加到 OE/YP。

    Resy (Reliable Embedded Systems Reference Distro) 3.0.1 multi-v7-ml ttymxc1
    
    multi-v7-ml login: root
    
    root@multi-v7-ml:~# sudo adduser anotheruser
    Changing password for anotheruser
    Enter the new password (minimum of 5 characters)
    Please use a combination of upper and lower case letters and numbers.
    New password:
    Re-enter new password:
    passwd: password changed.
    
    root@multi-v7-ml:~# id anotheruser
    uid=1001(anotheruser) gid=1001(anotheruser) groups=1001(anotheruser)
    root@multi-v7-ml:~#
    
    root@multi-v7-ml:~# sudo visudo -f /etc/sudoers.d/anotheruser
    
    add this lines:
    # users ins anotheruser group can do this:
    anotheruser ALL=(ALL) NOPASSWD: ALL
    
    root@multi-v7-ml:~# logout
    
    Resy (Reliable Embedded Systems Reference Distro) 3.0.1 multi-v7-ml ttymxc1
    
    multi-v7-ml login: anotheruser
    Password:
    multi-v7-ml:~$ whoami
    anotheruser
    multi-v7-ml:~$ id
    uid=1001(anotheruser) gid=1001(anotheruser) groups=1001(anotheruser)
    multi-v7-ml:~$ sudo ls /
    bin  boot  dev  etc  home  lib  media  mnt  my-core-image-minimal  opt  proc  run  sbin  sys  tmp  usr  var
    multi-v7-ml:~$
    

    【讨论】:

    • 嗨。请在下面查看我的评论。
    【解决方案4】:

    请参阅以下内容。 idh 是我的新用户,但它有许多“权限被拒绝”消息。所以我不能复制一些文件。但是,如果您看到我的 root 帐户,则没有错误。

    colibri-imx6ull login: idh
    Password:
    Last login: Sat May  2 12:13:20 UTC 2020 on ttymxc0
    -sh: /etc/profile.d/utf8.sh: Permission denied
    colibri-imx6ull:~$ cp /usr/bin/precept/*.* .
    cp: can't open '/usr/bin/precept/SSID-psk.config': Permission denied
    cp: can't open '/usr/bin/precept/flash.sh': Permission denied
    cp: can't open '/usr/bin/precept/gettysburg10.wav': Permission denied
    cp: can't open '/usr/bin/precept/run-htrc.sh': Permission denied
    cp: can't open '/usr/bin/precept/wifi.sh': Permission denied
    colibri-imx6ull:~$ ls /home
    idh   root
    colibri-imx6ull:~$
    
    colibri-imx6ull login: root
    Password:
    Last login: Sat May  2 12:15:11 UTC 2020 on ttymxc0
    root@colibri-imx6ull:~# cp /usr/bin/precept/*.* .
    root@colibri-imx6ull:~# ls /home
    idh   root
    root@colibri-imx6ull:~#
    

    我想将权限授予新用户,例如 root 帐户。如果您知道如何在 Yocto 中授予此权限,请告诉我。

    【讨论】:

    • 我们还没有实现这是 Yocto,因为您的问题陈述从“sudo”用户更改为“权限”。您可以尝试将您的 idh 用户添加到您的 sudoers 中吗?然后这个用户可以做一些类似“sudo cp”的事情,这应该可以工作......但是......我认为你还有另一个权限问题。
    猜你喜欢
    • 1970-01-01
    • 2021-10-20
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多