2

If I'm not mistaken, the --prefix option of useradd should allow me to change the etc files from the directory I select, but it strangely adds an extra /.

I'm using Linux Mint 21.1 mate 64bit version if anybody asks.

The entire command I execute is this one:

useradd -R /home/user/fakeroot -P  /home/user/Desktop newuser

And this is the output I get

useradd: /home/user/Desktop//etc/passwd.37507: No such file or directory
useradd: cannot lock /home/user/Desktop//etc/passwd; try again later.

How can I get rid of that extra /?

1 Answer 1

4

The extra / is irrelevant. Consecutive / are collapsed into a single one with no error message and no problem. For instance:

$ pwd
/home/terdon
$ cd ///////////////etc
$ pwd
/etc
$ cd //////usr/////local//////bin
$ pwd
/usr/local/bin

Now, the -P option of adduser is:

-P, --prefix PREFIX_DIR

Apply changes to configuration files under the root filesystem found under the directory PREFIX_DIR. This option does not chroot and is intended for preparing a cross-compilation target. Some limitations: NIS and LDAP users/groups are not verified. PAM authentication is using the host files. No SELINUX support.

But the -R option is:

-R, --root CHROOT_DIR

Apply changes in the CHROOT_DIR directory and use the configuration files from the CHROOT_DIR directory. Only absolute paths are supported.

I suspect that it doesn't make sense to use both of them, they basically do the same thing in a different way. I don't know the details here, and I may be wrong, but based on your output, it looks like the -P is overwriting the -R. Very probably, both options set the same variable in adduser's code, and the one you gave last overwrites the previous one.

Presumably, you have a valid chroot environment set up under /home/user/fakeroot, but because of the -P /home/user/Desktop you aren't using it and adduser is looking for /home/user/Desktop/etc instead of /home/user/fakeroot/etc.

I think you only want to use one of those two options and not both. If you explain what you are really trying to achieve, what the end result you're looking for is, we might be able to help more.

4
  • Thanks for your answer, what I'm trying to do is see if can manage the users of a chroot environment using etc files outside it
    – mrdaemon
    Commented Apr 15, 2023 at 9:43
  • @mrdaemon oh, no, you can't. That's the whole point of a chroot environment, also know as a chroot jail, you don't have access to anything outside it.
    – terdon
    Commented Apr 15, 2023 at 10:43
  • OTOH, if -R does a chroot() (for whatever reason), I suppose it might be possible that -P would just work after it. I.e. useradd -R /foo -P /bar would make changes in (the global) /foo/bar/etc/passwd. But I'm really just guessing, and the combination would likely be of a rather niche use.
    – ilkkachu
    Commented Apr 17, 2023 at 19:31
  • Yeah, I don't really know either @ilkkachu, but based on what the OP shows, it looks like both -R and -P work in the same way, possiblhy setting the same variable in the code so that one overwrites the other.
    – terdon
    Commented Apr 18, 2023 at 9:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .