Getting or Editing Sudo Rights for a User.
Summary
Sudo allows a linux user to run commands as root temporarily. This guide will show you how to gain these for a user if they cannot sudo.
Requirements
- Linux Operating System (Tested on EndeavourOS)
- Root Access
- Text Editor
Step by Step Guide
Enter/Become Root
su - rootEnter your Root password when prompted.
This will create a root session and move you into root home directory1. The file you will edit requires Root access.2
Edit the Sudoers File
vim /etc/sudoersUse an editor3 on the sudoers file4.
This file should be the same for most, if not all Linux Distributions.
Add or Modify Sudo Users
Look for Line: ## User privilege specification Under root ALL=(ALL:ALL) ALL,
add your user.
`<user> ALL=(ALL:ALL) ALL`Press i to be able to type in text. Copying the existing format for Root,
we are giving your user full sudo rights.5
Save your Edits
Press Esc then : then type wq then press Enter6
This will save the file and exit you from vim.
You have Finished
You may now exit back to your user.
Conclusion
You may now use sudo for any commands you want to run as root or are too lazy to get proper access in place for with user/s you have added to the sudoers list. Happy Linuxing! You will have to enter your user password to run a sudo'd command. It seems to have a "idle" period where you don't need to enter it for a while if you keep using sudo.
Notes
su - rootthesuis actually somewhat related to sudo, and it has some other usesman su, here, we are using it in conjunction with-(-l --login) to login to root, we don't actually need-for this guide, as we aren't doing anything in root's home directory, so we could've usedsu rootinstead if we wanted. We could also omitrootassudefaults toroot.- If you don't: You'll get read access to sudoers, and you'll edit the file only to find out you can't save. And I'll just add that keeping the access/owner to the file/s unchanged is probably better than not.
- The editor can be whatever you want, depending on what you like to use or what is installed. Nano can be popular.
- If you already have sudo rights, you could just
sudo nano /etc/sudoersdirectly. - There's a lot more that can be done here, such as restricting what commands can be sudo'd, allowing sudo for groups, the file may tell you what you can do. Or just allow full access because why not.
- This will depend on your editer.
Ctrl-XEnterEnterfor Nano users.
This guide was written by u/DesPartedNecturm (opens in a new tab).