chroot option for loginutils

Tito farmatito at
Thu May 12 20:09:56 UTC 2011

On Thursday 12 May 2011 20:22:54 Sergey Naumov wrote:
> Hello.
> I recently asked whether adduser / addgroup / passwd can be used to
> set up users/groups on a target system from host machine. It is rather
> simple to add root user and create password with htpasswd, but if I
> want to create several users like quagga, snmp, stunnel and so on I
> need to do it "by hands". I have created a draft patch to busybox to
> support "-C root " option for adduser, addgroup, passwd, deluser,
> delgroup instead of reinventing the bicycle. If it is interesting for
> somebody I can refurbish it.
> Any suggestions are welcomed.
> Sergey Naumov.

I think this is rather easy to achieve:
1) change the  paths  in libbb.h

#ifndef _PATH_PASSWD
#define _PATH_PASSWD  "/etc/passwd"
#ifndef _PATH_GROUP
#define _PATH_GROUP   "/etc/group"
#ifndef _PATH_SHADOW
#define _PATH_SHADOW  "/etc/shadow"
#define _PATH_GSHADOW "/etc/gshadow"

to what is suitable for you target system e.g $HOME/new_target/etc/passwd

2) compile a separate busybox binary to be used only during setup
     with all loginutils you need enabled and using bb's internal pwd_grp functions
     and name it pwd_setup 

3) create the needed empty files on the target filesystem
4) create a script calling your pwd_setup binary to add users, groups, passwd etc
    in loop for all the users you like.

Just an idea, but should work without adding code to bb.


More information about the busybox mailing list