如何在 yocto 中添加用户并重新设置 root 用户?
How to add an user and re set the root user in yocto?
我喜欢为我的 yocto 项目的内置用户做一些事情:
1.) 将 root 的密码设置为 "abc"
2.) 将 ssh 登录表单 /bin/sh 的根 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"
知道如何完成这项工作吗?
您可以在主配方中使用 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;"
我以你的例子为例,做了两处小改动以使其正常工作。
首先,我删除了 inherit extrauser
,这在使用 useradd 时不是必需的。这使得 bitbaking 食谱失败了;用户名无效。我将用户名更改为 custom
,一切正常。
检查生成的 myuser_1.0-r0.0_armv5e.ipk
时,我发现 myuser_1.0-r0.0_armv5e.ipk/control.tar.gz/preinst
中有一个预安装脚本可以创建您的用户。
我喜欢为我的 yocto 项目的内置用户做一些事情:
1.) 将 root 的密码设置为 "abc"
2.) 将 ssh 登录表单 /bin/sh 的根 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"
知道如何完成这项工作吗?
您可以在主配方中使用 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;"
我以你的例子为例,做了两处小改动以使其正常工作。
首先,我删除了 inherit extrauser
,这在使用 useradd 时不是必需的。这使得 bitbaking 食谱失败了;用户名无效。我将用户名更改为 custom
,一切正常。
检查生成的 myuser_1.0-r0.0_armv5e.ipk
时,我发现 myuser_1.0-r0.0_armv5e.ipk/control.tar.gz/preinst
中有一个预安装脚本可以创建您的用户。