Specify uid when creating the user via useradd

On my ubuntu24.04, the user created via useradd always has uid=1000.
However, the uid I observed entering chroot is the same as my own uid,
which is not 1000. Therefore, tools like sudo will fail because it
cannot recognize what user it is.

This commit fixes the issue by forcing the uid to be the same as the
outer one when creating the user via useradd.
This commit is contained in:
Tommy Chiang 2025-01-01 07:44:02 +08:00
parent dba98d948b
commit b818c44cbd
No known key found for this signature in database
GPG Key ID: 2CAA28B5410E84A4

View File

@ -122,7 +122,7 @@ RunWrappedScript()
# Allow normal user to sudo without a password. We may need to add the
# normal user, as it probably isn't created by debootstrap
$schroot -u root -- useradd -m $USER || :
$schroot -u root -- useradd -m $USER -u $(id -u) || :
$schroot -u root -- \
/bin/sh -c "echo '$USER ALL=(ALL) NOPASSWD:ALL'>/etc/sudoers.d/nopasswd-$USER"
$schroot -u root -- chmod 400 /etc/sudoers.d/nopasswd-$USER