小编典典

如何在yocto中添加用户并重新设置root用户?

linux

我喜欢为yocto项目的内置用户做一些事情:

1.)将root用户的密码设置为“ abc”

2.)将ssh登录表单/ bin / sh的根shell设置为/ bin / bash

3.)使用密码“ xyz”添加用户“ customUser”

认为简单的食谱可以做到这一点。到目前为止,我尝试了@ myUser.bb:

SUMMARY = "admin + user"
SECTION = "USR"
LICENSE = "CLOSED"

inherit extrausers useradd

# how to
# pw: abc
# at bash: usermod -p $(openssl passwd abc) root
# get a salted hash: openssl passwd abc
# one possible result: 1Cw5PHLy76ps2
# the command now looks: usermod -p 1Cw5PHLy76ps2 root

# set image root password
EXTRA_USERS_PARAMS = "usermod -p 1Cw5PHLy76ps2 root;"

USERADD_PACKAGES = "${PN}"

# password
# "xyz"
# openssl passwd xyz
# result: y5UyLBO4GNAwc

USERADD_PARAM_${PN} = "-u 1200 -d /home/customUser -r -s /bin/bash -p y5UyLBO4GNAwc customUser"

do_install_append () {
    install -d -m 755 ${D}${datadir}/customUser

    # The new users and groups are created before the do_install
    # step, so you are now free to make use of them:
    chown -R customUser ${D}${datadir}/customUser

    # groups
    # chgrp -R group1 ${D}${datadir}/customUser
}

FILES_${PN} = "${datadir}/*"

#ALLOW_EMPTY_${PN} = "1"

任何想法如何做到这一点?


阅读 1444

收藏
2020-06-03

共1个答案

小编典典

我以您的示例为例,进行了两个小更改以使其正常工作。

首先,我删除了inherit extrauser,使用useradd时不需要这样做。这使配方的烘焙失败了;用户名无效。我将用户名更改为custom,一切正常。

检查结果时myuser_1.0-r0.0_armv5e.ipk,我可以看到其中有一个预安装脚本myuser_1.0-r0.0_armv5e.ipk/control.tar.gz/preinst将创建您的用户。

2020-06-03