I am presuming you are quite new to Linux.
You follow some tutorial on the internet that tells you to install a certain program or run some command. Probably it is something to do with a server.
But when you run the command, you encounter this error:
E: Could not open lock file /var/lib/dpkg/lock-frontend – open (13: Permission denied)
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), are you root?
A similar error is this one:
dpkg: error: required read/write access to the dpkg database directory /var/lib/dpkg
E: Sub-process dpkg –set-selections returned an error code (2)
E: Executing dpkg failed. Are you root?
Both errors ask you the same question: are you root? And that’s the answer to this problem. Become root.
Become root to avoid this error
How do you become root in Ubuntu or Debian? You use the sudo command.
Yes, that’s it. Whatever command you were running, just add sudo before it.
It will ask you to enter your user account password. Please keep in mind that nothing gets displayed on the screen when you type the password and that’s okay.
There is nothing wrong with your system. In most Linux systems, password typing doesn’t show the usual asterisks or anything of that sort as a ‘security feature’.
Just type your password and press enter after it. If the password was typed correctly, you should be able to run the command now.
You can even use this handy Linux command line trick to run a previous command with sudo:
That was simple and works immediately, unless you do not have sudo access. Then, you’ll see a different error.
Seeing a ‘User is not in sudoer file’ error?
When you install Ubuntu, you have to create a user account. This user is automatically granted sudo power to run commands as root when required.
This happens on Ubuntu desktop, not servers. Most server distributions will have a separate root account. If you create a regular account separately, you’ll have to add the user to sudoer so that this normal user can use sudo.
In the screenshot above, I had created this additional user but did not add it to the sudo group. This means that user ‘prakash’ here does not have rights to use the sudo command and hence the system complains that ‘prakash is not in sudoers file’.
Where is the incident reported?
An incorrect sudo attempt is added to the system logs. It logs the user name, the virtual terminal number, location from where the command was run and which command was run.
The location of these logs differ from distribution to distribution.
Normally, you may find it in journalctl logs or /var/log/auth.log file in Ubuntu, /var/log/audit/audit.log file in Fedora.
What can you do if a user is not in sudoer list?
What can you do when you cannot use sudo with the current user account? First, verify if the user has sudo rights or not. If not, here are some options for you:
- Log in as root or switch to root (if you have root password).
- Add the user into sudoer list (if you have admin/sudo rights from some other user account).
- If you are in multi-user Linux system and do not have root or sudo access yourself, ask your sytem administrator to either grant your user sudo access or install the application you wanted to install.
Did this help?
Sudo is a very comprehensive security mechanism, and it is much more than just allowing a normal user to become root. It helps in auditing the system to know which user ran which command with sudo. It can also be configured to allow a certain user to run only certain commands with sudo.
You won’t see such granular sudo configuration on desktop Linux where it is preconfigured to allow any user in the sudo group to run any command as root with sudo. More on sudo in some other article.
I hope while solving this classic beginner problem, you get some initial insights into the sudo command. Let me know if you have further questions on this topic in the comment section.