Non-root user on Arch Linux
After installing Arch Linux, I added a non-root user with sudo
privileges and with privileges to shutdown and restart the machine.
Traditionally in Linux systems one creates a non-root user for regular operations. Even in cases where only one person uses the system, having a safeguard against accidentally running dangerous commands as root is nice.
Adding the user
Add a new user with a home directory and bash
for a login shell. Set the new user's password. Optionally exit the root session and test logging in as the new user.
useradd -m -s /bin/bash MyUsername passwd MyUsername # Optionally see the new home directory ls /home
Root access
Install the sudo
package. Edit the sudo
configuration file with the special visudo
utility per below. Sources recommend doing otherwise, but editing /etc/sudoers
directly also seems to work. Add the new user to the wheel
group. Optionally test running commands as root by prefixing them with sudo
when logged in as the new user.
# Install sudo pacman -S sudo # Uncomment the line "%wheel ALL=(ALL:ALL) ALL" EDITOR=vim visudo usermod -a -G wheel MyUsername
Power privileges
For convenience the non-root user should have the ability to shut down and reboot the system. Install the polkit
package.
pacman -S polkit
Surprisingly without enabling any service the non-root user now has the ability to use the shutdown
and reboot
commands. Perhaps they can now run other commands as well. There are certainly many things I still do not understand about polkit
.
References
- The installation guides referenced in the initial Arch installation article cover setting up non-root users rather than treating it as a separate process.
- The arch wiki documents how to add users. It includes several examples.
- How to install and configure
sudo
to allow non-root users to run commands as root. - How to install and configure
polkit
. Of only tangential interest to this task.