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

时间:2017-05-18 09:30:22

标签: linux yocto bitbake

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

1。)将root的密码设置为“abc”

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

3.。)添加用户“customUser”,密码为“xyz”

认为一个简单的食谱可以做到这一点。到目前为止,我尝试了@ 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"

知道如何完成这项工作吗?

2 个答案:

答案 0 :(得分:2)

您可以在主食谱中使用EXTRA_USERS_PARAMS全球。

inherit extrausers
EXTRA_USERS_PARAMS = " useradd customUser1; \
                       useradd customUser2; \
                       usermod  -p 'Password_1' customUser1; \
                       usermod  -p 'Password_2' customUser2; \
                       usermod  -a -G sudo customUser1; \
                       usermod  -a -G sudo customUser2;"

答案 1 :(得分:2)

我举了你的例子并做了两处小改动让它发挥作用。

首先,我删除了inherit extrauser,这在使用useradd时并不是必需的。这使得配方失败了;用户名无效。我将用户名更改为custom,一切都很好。

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