15

I just installed Arch. Works great. I created a new user, logged in with it and now I'm trying to install several things with pacman. But I keep getting the error: error: you cannot perform this operation unless you are root. I can use pacman with root just fine, but is there a way to allow my new user to perform these actions?

I tried logging into root and using gpasswd:

gpasswd -a jack root

but that didn't do anything.

1
  • 1
    As a general note, the Arch Linux wiki is really useful and detailed. Commented Sep 1, 2012 at 11:37

3 Answers 3

19

You should read the Arch Wiki page on sudo.

sudo ("substitute user do") allows a system administrator to delegate authority to give certain users (or groups of users) the ability to run some (or all) commands as root or another user while providing an audit trail of the commands and their arguments.

You can install sudo from the repositories and then configure it to allow your user, jack, access to privileged commands by editing /etc/sudoers. Make sure you do this using the visudo command.

To give the user jack full root privileges, you would add this line:

jack ALL=(ALL) ALL
0
10

What I usually do is enable root privileges for a specific group. That way you can just add users you want root privileges to that group.

Edit /etc/sudoers with visudo and add (or comment out):

%wheel      ALL=(ALL) ALL

Then add your user to that group:

gpasswd -a jack wheel
1
  • 1
    Even though the answer that is marked as accepted and it will work, I believe this answer is a better due to using groups over modifying sudoers. Commented Aug 6, 2018 at 13:03
0

I can use pacman with root just fine, but it there a way to allow my new user to perform these actions?

You could create your $USER, adding them to the wheel group alone:

useradd -Ng wheel --create-home --no-log-init $USER

Then update /etc/sudoers as suggested by Eric Lennartsson. But if you're looking for a programmatic approach you can instead create a file in /etc/sudoers.d like:

echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/dont-prompt-$USER-for-password

The method above was suggested by Boris in Ask Ubuntu and it doesn't require use of visudo at all. When using it with pacman prefix the commands with sudo like:

sudo pacman -S docker docker-compose

You must log in to answer this question.

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