I need to install a package. For that I need root access. However the system says that I am not in sudoers file. When trying to edit one, it complains alike! How am I supposed to add myself to the sudoers file if I don't have the right to edit one?
I have installed this system and only administrator. What can I do?
Edit: I have tried visudo already. It requires me to be in sudoers in the first place.
amarzaya@linux-debian-gnu:/$ sudo /usr/sbin/visudo
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things: #1) Respect the privacy of others. #2) Think before you type. #3) With great power comes great responsibility.
[sudo] password for amarzaya:
amarzaya is not in the sudoers file. This incident will be reported.
amarzaya@linux-debian-gnu:/$ 2 9 Answers
It would be something of a security hole if you could add yourself to /etc/sudoers without having sudo or root access. Basically then anyone could make themselves root.
Basically you need to ask the administrators of that machine to add you, or to install the package for you, as per the policies of the site.
You should also be sure to use visudo to edit the sudoers file - it checks that the syntax is correct before writing the file. And you can use editors other than vi with visudo. It will by default use whatever you have set as $EDITOR and if you don't have it set you could do
# EDITOR=nano visudoto use the nano editor instead.
3Login as root and use /usr/sbin/visudo to edit the file and add your username. Normal vi/vim will not be able to edit the file.
The easiest way is to just go down until you see the line "root ALL=(ALL) ALL" and add yourself under that with the same syntax (yourusername ALL=(ALL) ALL). Or, you can read the sudoers manpage if you want to give yourself more specific privileges.
Just typed the command:
$ suAnd asked for the password "root". Typed and boom... It worked!
This problem was my mistake. Due to be back at the facility at the time I created the username and password.
1Perhaps the easiest way, once you're root, is:
echo 'amarzaya ALL=(ALL) ALL' >> /etc/sudoers 1 If your sudoers file already contains this kind of line
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALLThen, the cleanest way of doing things is probably to grant the admin group to your user. For instance, to add user oracle to the admin group:
usermod -aG admin oracle 5 In case you can still get root access using su, you can use this one-liner to add yourself to /etc/sudoers/:
su -c 'echo $USER ALL=(ALL)ALL >> /etc/sudoers'To activate the change, log out and in again. For example end your the X Session or log out via shell enter exit.
If you cannot use the sudo command, then you can use the following method:
- Press Ctrl+Alt+F1
- Log the user out if the user is not root
- Log in as root
- Use root privileges
- Log out (
exit) – Ctrl+Alt+F7 to get to the GUI
All you need is add your <username> to whell group.
# usermod -aG whell usernameThen login with your username and enjoy :)
Sign in using the following first:
$ suThen go ahead with:
$ sudo apt-get updateor whatever as normal
4