I have created a recipe for adding a new user.
inherit extra users
SRC_URI = "file://.bashrc"
FILES_${PN} = "/home/user/.bashrc"
EXTRA_USERS_PARAMS = "useradd -u 1200 -d /home/user/ -p '' -s /bin/rbash user"
ROOTFS_POSTPROCESS_COMMAND += "modify_default_bashrc;"
modify_default_bashrc () {
mkdir -p {D}/home/user
install ${WORKINGDIR}/.bashrc ${D}/home/user
}
The goal is to create a non root user, who can run a restricted set of commands. To do this I set rbash as default, also I created /home/user/bin and put links to the set of commands that this user can run. The final step was to set the PATH variable to /home/user/bin in the /home/user/.bashrc
Unfortunately after I run my recipe the .bashrc file is set to a default one and I don’t know how to modify it.
How can I add a custom .bashrc for a custom user?
or
Is there a better way to restrict a user?
5
you can use the usermod
command inside the creation script to alter your new user default shell to custom-shell.
first you need to add the custom shell to /etc/shells
(this file contains valid pathnames to login shells).
after you can alter the default user shell to the new one
sudo usermod --shell /bin/bash ${username}
for more information you can read this article from GeeksForGeeks
2