0
0
0
s2sdefault

In order to avoid logging in as the root user, we have the sudo command to allow us to run commands as the root user, thus allowing us accomplish admin tasks, with our own, non-root users. Most of the time, the sudo command will prompt you for your password, just to make sure. While this is typically just fine, it annoys the heck out of me. In this article, we will cover editing the sudoers file, and getting rid of the password prompt.

What is Sudo, really?

According to the sudo website: "Sudo (su "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."

xkcd sudo comic

Thanks XKCD for the comic

So how DO we get rid of the password prompt? In the end, the process is rather quite simple:

  1. Run command:
    • sudo visudo
    • Depending on what Linux distro you are using, and whether or not you have ever run visudo before, you may opr may not get a prompt asking you about what text editor you want to use to edit the sudoers file. If you are unsure what to pick, I would suggest using nano.
  2. Go down to the bottom of the file, add the following line:
    • <user> ALL=(ALL) NOPASSWD: ALL
    • Note: replace <user> with your username
  3. Save and exit the file
  4. Run command:
    • sudo -k
    • This will clear the exiting password cache
  5. You're done!
  6. To test, run command:
    • sudo ls
    • You should not be prompted for a password

While it is indeed entirely possible to go ahead and manually edit the /etc/sudoers file manually, I would not suggest doing so. If you use visudo , it will actually check the syntax of the file to make sure it was properly edited; if there are any errors in the syntax, it will NOT save the file, and it will give you an error. On the other hand, if you manually edit the sudoers file, there is NO such syntax checking, and if there ARE errors, you will not be able to use the sudo comnmand to repair the file (I learned this from personal experience). You will either need to reinstall the OS, or if you are lucky, you can boot from a live Linux USB (or CD/DVD), and edit the file from there.

So... What else can you do with the sudoers file? You can do a whole lot more than just remove the password prompt. You can really get a granular as you want... You could have some users not require password for some commands, but still need the password for others. You could do the same based on the source IP of the terminal client (like SSH).

But first, if you considering getting more granular, this means you have other users working on the device, and you will likely NOT remove the sudo prompt for ALL users (and if you are, you should consider reconsidering what you are about to do). So this means there will be inevitable password entry errors, and you should put the following line in at the end of the 'defaults' in the sudoers file:

Defaults insults

This will gently and comically insult the user everytime they put in the wrong password.

Now on to the more "practical" granular configuration...

It is hard to try to describe a "typical" sudoers file. There just isn't any "typical", other than what's there by default (which varies dependent upon your distro). But I will try to show some "typical-type" entries on some of the more granular end of the scale. Consider the following sudoers file:

User_Alias     ADMINS = jon, user1, user2
Runas_Alias    OP = root, user3
Host_Alias     INTERNAL = 192.168.1.0/255.255.255.0
Cmnd_Alias     POWER = /sbin/reboot, /sbin/poweroff

ADMINS ALL=ALL

#The users in the ADMINS group can run any command from any terminal.

user1 ALL=(OP) ALL

# The user 'user1' can run any command from any terminal as any user in the OP group (root or user3).

user2 INTERNAL=(ALL) ALL

# user 'user2' may run any command from any machine in the INTERNAL network, as any user.

user3 ALL= POWER

# user user3 may run 'reboot' and 'poweroff' from any machine.

user4 ALL=(ALL) ALL

# user user4 may run any command from any machine acting as any user. (like Ubuntu)

This is just a basic example of what you can do, you can get very granular, and VERY complex. Just remember to ALWAYS edit the file via the 'visudo' command, rather than editing the file directly.

A couple last sudo commands:

sudo -l

Note: That's a lowercase 'L', not an uppercase 'i'

This command will list the sudo "permissions" you have.

sudo -k

This will clear the cached password.

Thanks for reading! Why don't you tell me some of the crazier sudo configs you've seen or done in the comments section...?

 

UPDATE KALI 2020

If you tried following this on the latest 2020 editions of Kali Linux, you will have probably noted that it doesn't seem to work as expected. from what I can tell, this is expected and by design. For the laatest version(s) of Kali, you need to run the following command:

sudo dpkg-reconfigure kali-grant-root

 

Comments  

# skaładanie komputera 2020-08-08 04:56
I think that is one of the so much significant information for me.
And i am glad studying your article. But wanna observation on few general issues, The website taste is great, the articles is truly great : D.
Just right process, cheers
Reply | Reply with quote | Quote
# fotografia 2020-08-08 23:28
I have read so many articles concerning the blogger lovers
except this paragraph is in fact a pleasant piece of
writing, keep it up.
Reply | Reply with quote | Quote
# trening 2020-09-06 18:13
Hello there! Would you mind if I share your blog
with my twitter group? There's a lot of people
that I think would really enjoy your content. Please let me know.

Cheers
Reply | Reply with quote | Quote
# recenzje komputerowe 2020-09-07 11:12
I constantly emailed this blog post page to all my contacts, for the reason that if like to read it after that my links will
too.
Reply | Reply with quote | Quote
# minimalizm 2020-09-23 20:15
Aw, this was a really nice post. Taking a few minutes and actual effort to make a great article… but what can I say… I hesitate a lot and don't seem to
get anything done.
Reply | Reply with quote | Quote
# fit life 2020-11-21 06:28
It's the best time to make some plans for the future and it's time to
be happy. I've read this post and if I could I desire to suggest you some interesting things or
advice. Perhaps you could write next articles referring to this article.
I wish to read even more things about it!
Reply | Reply with quote | Quote

Add comment


Security code
Refresh

0
0
0
s2sdefault