本文介绍了如何在yocto中添加用户并重新设置root用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I like to do some things for the build-in users of my yocto project:

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

1.) set a password for root to "abc"

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

2.) set the root shell for ssh login form /bin/sh to /bin/bash

3.)添加密码为"xyz"的用户"customUser"

3.) add the user "customUser" with password "xyz"

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

Think a simple recipe can do this. So far I tried @ 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"

有什么想法要完成吗?

推荐答案

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

I took your example and made two small changes to get it to work.

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

First, I removed inherit extrauser, this isn't necessary when working with useradd. That made bitbaking the recipe fail; the username was invalid. I changed the username to custom, and everything builds fine.

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

When inspecting the resulting myuser_1.0-r0.0_armv5e.ipk, I can see that there are a preinstall script in myuser_1.0-r0.0_armv5e.ipk/control.tar.gz/preinst that will create your user.

这篇关于如何在yocto中添加用户并重新设置root用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 02:26