如何通过 Yocto 在构建时添加用户?
How to add users at build time via Yocto?
我正在开发一个带有 i.MX6 DL、Yocto Pyro 和内核 4.14.16 的定制板,我正在尝试弄清楚如何添加新用户。我已尝试此处提供的建议: 无济于事。我还按原样尝试了 运行 演示 useradd-example.bb 配方(位于 recipes-skeleton 层中),但也没有用。
它编译并且我可以构建图像,但是当我尝试以任何新用户身份登录时,我的登录不正确。如果我以 root 身份登录,我在 /home/ 目录中看不到任何文件夹(我已将 root 主文件夹移动到 /root)。我猜有些东西不见了。
这是我使用的食谱:
SUMMARY = "Add the user accounts that the production printer will need."
LICENSE = "CLOSED"
#inherit extrausers
#
#EXTRA_USERS_PARAMS = "\
# useradd -P Z2tQc0Ewto0c. mi_printer; \
# usermod -P Z2tQc0Ewto0c. root;"
#SUMMARY = "Example recipe for using inherit useradd"
#DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
#SECTION = "examples"
#PR = "r1"
#LICENSE = "MIT"
#LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
SRC_URI = "file://file1 \
file://file2 \
file://file3 \
file://file4"
S = "${WORKDIR}"
PACKAGES =+ "${PN}-user3"
#EXCLUDE_FROM_WORLD = "1"
inherit useradd
# You must set USERADD_PACKAGES when you inherit useradd. This
# lists which output packages will include the user/group
# creation code.
USERADD_PACKAGES = "${PN} ${PN}-user3"
# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
# you inherit useradd.
# USERADD_PARAM specifies command line options to pass to the
# useradd command. Multiple users can be created by separating
# the commands with a semicolon. Here we'll create two users,
# user1 and user2:
USERADD_PARAM_${PN} = "-u 1200 -d /home/user1 -r -s /bin/bash user1; -u 1201 -d /home/user2 -r -s /bin/bash user2"
# user3 will be managed in the useradd-example-user3 pacakge:
# As an example, we use the -P option to set clear text password for user3
USERADD_PARAM_${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/bash -P 'user3' user3"
# GROUPADD_PARAM works the same way, which you set to the options
# you'd normally pass to the groupadd command. This will create
# groups group1 and group2:
GROUPADD_PARAM_${PN} = "-g 880 group1; -g 890 group2"
# Likewise, we'll manage group3 in the useradd-example-user3 package:
GROUPADD_PARAM_${PN}-user3 = "-g 900 group3"
do_install () {
install -d -m 755 ${D}${datadir}/user1
install -d -m 755 ${D}${datadir}/user2
install -d -m 755 ${D}${datadir}/user3
install -p -m 644 file1 ${D}${datadir}/user1/
install -p -m 644 file2 ${D}${datadir}/user1/
install -p -m 644 file2 ${D}${datadir}/user2/
install -p -m 644 file3 ${D}${datadir}/user2/
install -p -m 644 file3 ${D}${datadir}/user3/
install -p -m 644 file4 ${D}${datadir}/user3/
# The new users and groups are created before the do_install
# step, so you are now free to make use of them:
chown -R user1 ${D}${datadir}/user1
chown -R user2 ${D}${datadir}/user2
chown -R user3 ${D}${datadir}/user3
chgrp -R group1 ${D}${datadir}/user1
chgrp -R group2 ${D}${datadir}/user2
chgrp -R group3 ${D}${datadir}/user3
}
FILES_${PN} = "${datadir}/user1/* ${datadir}/user2/*"
FILES_${PN}-user3 = "${datadir}/user3/*"
# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
开头用 extrausers
注释掉的简短的 blurb 是我在网络上的其他地方看到的我尝试过的东西。理想情况下,我想添加一个名为 printer 的用户,但只要我能正常工作,我就可以完成剩下的工作。
更新:最终配方如下:
SUMMARY = "Add the user accounts that the production printer will need."
LICENSE = "CLOSED"
SRC_URI = "file://file1 \
file://file2"
S = "${WORKDIR}"
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM_${PN} = "-u 1200 -d /home/user1 -m -s /bin/sh -p Z2tQc0Ewto0c. mi-printer"
GROUPADD_PARAM_${PN} = "-g 880 group1"
do_install () {
install -d -m 755 ${D}${datadir}/mi-printer
install -p -m 644 file1 ${D}${datadir}/mi-printer/
install -p -m 644 file2 ${D}${datadir}/mi-printer/
# The new users and groups are created before the do_install
# step, so you are now free to make use of them:
chown -R mi-printer ${D}${datadir}/mi-printer
chgrp -R group1 ${D}${datadir}/mi-printer
}
FILES_${PN} = "${datadir}/mi-printer/*"
# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
密码哈希是通过运行openssl passwd password
获得的
你的问题好像由两部分组成:
如何添加用户
您示例中的 useradd
部分已经这样做了;查看 /etc/passwd
文件,您会发现 user1
如何设置密码
您必须使用 -p
选项指定密码并确保已提供登录名 shell(例如不是 /bin/false
):
USERADD_PARAM_${PN} = "-s /bin/bash -p '$HzRkQcjT$/jV0VB4GJd1b3DTXfCYNo.' user1"
但在大多数情况下你不需要步骤2,因为在嵌入式系统上通常只有服务用户而没有普通用户。
示例食谱具有误导性
示例食谱告诉您在 ${D}${datadir}/username
中做各种事情,您希望这是理智的事情。
但是,${datadir}
实际上是 /usr/share
,所以请看一下图像中的 /usr/share/mi-printer
。那就是你的东西实际所在的地方。
我刚刚在我的食谱中用 /home
替换了 ${datadir}
,这解决了所有问题。
如果你有一个不同的包,然后在 newly-created 主目录中安装东西,请在其中使用 来放弃主目录本身的所有权。
我正在开发一个带有 i.MX6 DL、Yocto Pyro 和内核 4.14.16 的定制板,我正在尝试弄清楚如何添加新用户。我已尝试此处提供的建议:
它编译并且我可以构建图像,但是当我尝试以任何新用户身份登录时,我的登录不正确。如果我以 root 身份登录,我在 /home/ 目录中看不到任何文件夹(我已将 root 主文件夹移动到 /root)。我猜有些东西不见了。
这是我使用的食谱:
SUMMARY = "Add the user accounts that the production printer will need."
LICENSE = "CLOSED"
#inherit extrausers
#
#EXTRA_USERS_PARAMS = "\
# useradd -P Z2tQc0Ewto0c. mi_printer; \
# usermod -P Z2tQc0Ewto0c. root;"
#SUMMARY = "Example recipe for using inherit useradd"
#DESCRIPTION = "This recipe serves as an example for using features from useradd.bbclass"
#SECTION = "examples"
#PR = "r1"
#LICENSE = "MIT"
#LIC_FILES_CHKSUM = "file://${COREBASE}/meta/COPYING.MIT;md5=3da9cfbcb788c80a0384361b4de20420"
SRC_URI = "file://file1 \
file://file2 \
file://file3 \
file://file4"
S = "${WORKDIR}"
PACKAGES =+ "${PN}-user3"
#EXCLUDE_FROM_WORLD = "1"
inherit useradd
# You must set USERADD_PACKAGES when you inherit useradd. This
# lists which output packages will include the user/group
# creation code.
USERADD_PACKAGES = "${PN} ${PN}-user3"
# You must also set USERADD_PARAM and/or GROUPADD_PARAM when
# you inherit useradd.
# USERADD_PARAM specifies command line options to pass to the
# useradd command. Multiple users can be created by separating
# the commands with a semicolon. Here we'll create two users,
# user1 and user2:
USERADD_PARAM_${PN} = "-u 1200 -d /home/user1 -r -s /bin/bash user1; -u 1201 -d /home/user2 -r -s /bin/bash user2"
# user3 will be managed in the useradd-example-user3 pacakge:
# As an example, we use the -P option to set clear text password for user3
USERADD_PARAM_${PN}-user3 = "-u 1202 -d /home/user3 -r -s /bin/bash -P 'user3' user3"
# GROUPADD_PARAM works the same way, which you set to the options
# you'd normally pass to the groupadd command. This will create
# groups group1 and group2:
GROUPADD_PARAM_${PN} = "-g 880 group1; -g 890 group2"
# Likewise, we'll manage group3 in the useradd-example-user3 package:
GROUPADD_PARAM_${PN}-user3 = "-g 900 group3"
do_install () {
install -d -m 755 ${D}${datadir}/user1
install -d -m 755 ${D}${datadir}/user2
install -d -m 755 ${D}${datadir}/user3
install -p -m 644 file1 ${D}${datadir}/user1/
install -p -m 644 file2 ${D}${datadir}/user1/
install -p -m 644 file2 ${D}${datadir}/user2/
install -p -m 644 file3 ${D}${datadir}/user2/
install -p -m 644 file3 ${D}${datadir}/user3/
install -p -m 644 file4 ${D}${datadir}/user3/
# The new users and groups are created before the do_install
# step, so you are now free to make use of them:
chown -R user1 ${D}${datadir}/user1
chown -R user2 ${D}${datadir}/user2
chown -R user3 ${D}${datadir}/user3
chgrp -R group1 ${D}${datadir}/user1
chgrp -R group2 ${D}${datadir}/user2
chgrp -R group3 ${D}${datadir}/user3
}
FILES_${PN} = "${datadir}/user1/* ${datadir}/user2/*"
FILES_${PN}-user3 = "${datadir}/user3/*"
# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
开头用 extrausers
注释掉的简短的 blurb 是我在网络上的其他地方看到的我尝试过的东西。理想情况下,我想添加一个名为 printer 的用户,但只要我能正常工作,我就可以完成剩下的工作。
更新:最终配方如下:
SUMMARY = "Add the user accounts that the production printer will need."
LICENSE = "CLOSED"
SRC_URI = "file://file1 \
file://file2"
S = "${WORKDIR}"
inherit useradd
USERADD_PACKAGES = "${PN}"
USERADD_PARAM_${PN} = "-u 1200 -d /home/user1 -m -s /bin/sh -p Z2tQc0Ewto0c. mi-printer"
GROUPADD_PARAM_${PN} = "-g 880 group1"
do_install () {
install -d -m 755 ${D}${datadir}/mi-printer
install -p -m 644 file1 ${D}${datadir}/mi-printer/
install -p -m 644 file2 ${D}${datadir}/mi-printer/
# The new users and groups are created before the do_install
# step, so you are now free to make use of them:
chown -R mi-printer ${D}${datadir}/mi-printer
chgrp -R group1 ${D}${datadir}/mi-printer
}
FILES_${PN} = "${datadir}/mi-printer/*"
# Prevents do_package failures with:
# debugsources.list: No such file or directory:
INHIBIT_PACKAGE_DEBUG_SPLIT = "1"
密码哈希是通过运行openssl passwd password
你的问题好像由两部分组成:
如何添加用户
您示例中的
useradd
部分已经这样做了;查看/etc/passwd
文件,您会发现user1
如何设置密码
您必须使用
-p
选项指定密码并确保已提供登录名 shell(例如不是/bin/false
):
USERADD_PARAM_${PN} = "-s /bin/bash -p '$HzRkQcjT$/jV0VB4GJd1b3DTXfCYNo.' user1"
但在大多数情况下你不需要步骤2,因为在嵌入式系统上通常只有服务用户而没有普通用户。
示例食谱具有误导性
示例食谱告诉您在 ${D}${datadir}/username
中做各种事情,您希望这是理智的事情。
但是,${datadir}
实际上是 /usr/share
,所以请看一下图像中的 /usr/share/mi-printer
。那就是你的东西实际所在的地方。
我刚刚在我的食谱中用 /home
替换了 ${datadir}
,这解决了所有问题。
如果你有一个不同的包,然后在 newly-created 主目录中安装东西,请在其中使用