4.3. Adding the LFS User

When logged in as user root, making a single mistake can damage or destroy a system. Therefore, the packages in the next two chapters are built as an unprivileged user. You could use your own user name, but to make it easier to set up a clean working environment, we will create a new user called zlfs as a member of a new group (also named zlfs) and run commands as zlfs during the installation process. As root, issue the following commands to add the new user:

groupadd zlfs
useradd -s /bin/bash -g zlfs -m -k /dev/null zlfs

This is what the command line options mean:

-s /bin/bash

This makes bash the default shell for user zlfs.

-g zlfs

This option adds user zlfs to group zlfs.

-m

This creates a home directory for zlfs.

-k /dev/null

This parameter prevents possible copying of files from a skeleton directory (the default is /etc/skel) by changing the input location to the special null device.

zlfs

This is the name of the new user.

If you want to log in as zlfs or switch to zlfs from a non-root user (as opposed to switching to user zlfs when logged in as root, which does not require the zlfs user to have a password), you need to set a password for zlfs. Issue the following command as the root user to set the password:

passwd zlfs

Grant zlfs full access to all the directories under $LFS by making zlfs the owner:

chown -v zlfs $LFS/{usr{,/*},var,etc,tools,zbuild}
[Note]

Note

In some host systems, the following su command does not complete properly and suspends the login for the zlfs user to the background. If the prompt "zlfs:~$" does not appear immediately, entering the fg command will fix the issue.

Next, start a shell running as user zlfs. This can be done by logging in as zlfs on a virtual console, or with the following substitute/switch user command:

su - zlfs

The - instructs su to start a login shell as opposed to a non-login shell. The difference between these two types of shells is described in detail in bash(1) and info bash.