How to Use Sudo without Password in Linux

Disable Sudo Password Featured

If you’re the only one using your Linux computer, why have it continuously nag you for your password? Let’s see how you can use sudo without having to type a password each time.

Note: we’ll see how to disable the sudo password in the latest version of Ubuntu. Details of the process may be different in other distributions.

Edit Sudoers File

To disable password checks when using sudo for your account, you must edit the “sudoers” file. It’s where access rights to thesudo command are defined for individual user accounts or user groups. It would be best if you didn’t try to edit the file directly, though. Instead, run your favorite terminal and enter:

Disable Sudo Password Sudo Visudo

Disable Sudo Password for Your Account

To stop sudo from asking you for your password, first, check whether there’s an existing rule with your alias. If there is, change it to what we’ll see next. If there isn’t, move to the end of the file and create a new rule there. It should look like:

For my alias, this rule was:

Disable Sudo Password Sudoers File

Save the changes and exit the editor. Since in our installation the editor was nano, we used Ctrl + O, followed by Ctrl + X.

Use Sudo without Password

That is all you have to do – from now on, sudo won’t ask for your password anymore, provided everything went according to plan and no typo thwarted our plans. Check it out with a command like sudo apt update, or by installing an app with sudo apt install as a test, for example:

Disable Sudo Password Sudo Test
Disable Sudo Password Test Installation

Don’t Disable Sudo Passwords for Everyone

If you’re sharing your computer with others, and you want to save them the hassle of also having to enter their password whenever they use sudo – don’t. In fact, there should only be one main user that has sudo privilege.

Sudo isn’t regarded anymore as a security measure against users with local access to our hardware. It’s not that hard to reset the root password if you have local access to a Linux installation. Instead, it’s there for the same reason as Windows’s annoying User Account Control: as a last protective layer between us, our computer, and potential chaos. And that’s because one wrong command can lead to the deletion of all our data, the destruction of our installation, or the unintended sharing of personal information.

Disabling the sudo password is only good for those who have a good experience with the Linux command line and are the only user on their computer.

We must stress that this removes this last protective barrier between a user and their own mistakes. We heavily suggest you also make a full backup of your system and all its data before doing that.

Related:

6 comments

  1. “If you’re the only one using your Linux computer, why have it continuously nag you for your password?”
    You may be the only one officially using your PC but there are many hackers that would like to use it too. If you disable the sudo password, you are making it easier for all kinds of bad actors to access your root functions.

    1. Yes, but as was mentioned in the article (and linked to an older piece), someone with physical access to your PC can get root access anyway through other means. Is someone – like the majority of desktop users – doesn’t “expose” their PC to the Internet through SSH or other “venues” through which sudo could be misused, it’s simply a UAC equivalent. The biggest threat to sudo-without-a-password is the person using the computer. If they’re knowledgeable and careful, password or no password will make no difference.

  2. I thought Linux was hackproof ?

    Besides, if there is nothing sensitive on the hacked machine, then it’s worth the risk to disable the password.

    1. “I thought Linux was hackproof ?”
      Not if you use a blank password.

      There may be nothing sensitive on your computer but if you do not use a strong password, it may become part of a botnet.

  3. “If you’re the only one using your Linux computer, why have it continuously nag you for your password? Let’s see how you can use sudo without having to type a password each time.”

    The easiest way of doing this is to simply use the ‘root’ account. Granted, it can be a little difficult to get the GUI to allow ‘root’ to login, but it’s (usually) not impossible…and if you don’t use the GUI, then there’s no problem. And then you never have to worry about access permissions again. (Please don’t anyone reply telling me of the “dangers” of using the ‘root’ account versus a regular user account…it’s all BS. See below.)

    That said, thanks for the into on how to disable having to type the password every time I need to use ‘sudo’…that’ll come in massively handy :-)

    “It would be best if you didn’t try to edit the file directly, though. Instead, run your favorite terminal and enter: sudo visudo”

    Heh. For the years that I’ve used Linux on and off, I’ve always edited the “sudoers” file directly…I’ve never used ‘visudo’. Oops :-)

    “In fact, there should only be one main user that has sudo privilege.”

    In fact, there really shouldn’t be *anyone* that has ‘sudo’ privilege. If you want to make changes that require ‘root’ privilege, you should be forced to switch to one of the TTY login screens and log in as ‘root’ to make the changes. The time needed to do so would give you lots of time to consider whether you *really* want to do what you’re trying to do…and would likely save a lot of disasters.

    “Sudo isn’t regarded anymore as a security measure against users with local access to our hardware. … Instead, it’s there for the same reason as Windows’s annoying User Account Control: as a last protective layer between us, our computer, and potential chaos. And that’s because one wrong command can lead to the deletion of all our data … or the unintended sharing of personal information.”

    Sorry, but there’s *nothing* to prevent a user from deleting all their data or sharing their personal info…since neither of those things require ‘root’ privileges, ‘sudo’ isn’t involved at all.

    “the destruction of our installation,”

    In fact, ‘sudo’ isn’t even much of a “protective layer” for that, as it won’t *prevent* anyone in the “sudoers” file from “destroying” the system; it is, at best, a delaying tactic. When a user gets the “you don’t have permission to do that” message, all they have to do is type “sudo !!”, hit enter and type their password, and the system-destroying command is on its way…and that’s taken, what, 5 seconds? 10? Big whoop.

    This is why I laugh every time I see a “Linux Guru” say something stupid like “Oh, you mustn’t use the ‘root’ account for everyday things, you can destroy the system. You need to create a normal user account and use ‘sudo’; that’ll prevent you from destroying the system”. No. It won’t. As I said, it’ll just delay the destruction by 5 or 10 seconds…but the destruction will still happen.

    “It’s not that hard to reset the root password if you have local access to a Linux installation.”

    Depends on whether or not the user account you have access to is in the “sudoers” file. If it isn’t, then you can’t reset the password to ‘root’. And if it is, then while you *can* reset the password to ‘root’, you don’t *need* to…you can already do everything ‘root’ can do via ‘sudo’.

    “We heavily suggest you also make a full backup of your system and all its data before doing that”

    Actually, making a backup only “before doing that” isn’t enough…it’s going to be at least a week before the inevitable happens and you trash the system (or part of it), so if the only backup you made is before you disabled the password for ‘sudo’, then you’ve just lost a week of data. If you disable the password for ‘sudo’, you need to be making a backup every day – which you really should be doing anyway – so that when you do trash your system, you’ve only lost one (possibly partial) day of data.

Leave a Comment

Yeah! You've decided to leave a comment. That's fantastic! Check out our comment policy here. Let's have a personal and meaningful conversation.