1

I have to use sudo a lot, and it gets exhausting typing the password when I've already entered it plenty of times. How do I make it so that once I've entered it once, it won't ask me again? I'm on Centos 7.

4 Answers 4

4

There are multiple ways to go about this. Here are a few:

Disable the password prompts

Ref: https://serverfault.com/questions/579296/how-do-i-disable-the-sudo-password-prompt)

Alter the timeout

Ref: Change default sudo password timeout

Elevate to root

sudo -i

This latter option is the closest match to your question, I suppose, but you may well find the timeout meets your needs.

4
  • I think I prefer changing the default sudo password timeout. First off, do I just add the line Defaults timestamp_timeout=30 anywhere in the file? Nov 26, 2019 at 20:08
  • If there's an existing Defaults entry, you should append that. Otherwise I'd tend to stick it up near the top, but I don't think it particularly matters where it goes.
    – bxm
    Nov 28, 2019 at 10:36
  • I always use sudo -s. What's the difference with sudo -i?
    – trent
    Nov 28, 2019 at 12:32
  • 1
    Can’t say I’ve ever used -s that I recall, but -i simulates the initial login, so presumably sets up the environment akin to if you did sudo su -.
    – bxm
    Nov 28, 2019 at 16:50
2
sudo -s 

Will leave you as root, be careful

2
  • 1
    Nice, but wouldn't it make sense to use sudo -i instead to ensure root's environment is set appropriately?
    – Murphy
    Nov 28, 2019 at 12:23
  • the only difference i can see right now is when iam using sudo -s , iam not losing my current working directory
    – Pat cm pro
    Nov 28, 2019 at 12:32
0

You could enable login for the root account. Be aware that there's a reason (or more than one) that this is disabled by default; you'll have to be sure what you do when you work as root permanently (even if it's only in a single terminal window). I absolutely discourage to start a Desktop environment or run user applications (like Office, browsers etc.) with root privileges, or otherwise make a habit of working as root by default. Log in on console when you need to, and log out as soon as you're done. Make sure the login features a different prompt than normal users, using the hash as prompt sign, and red color e. g. for the hostname.

That said, setting a password for root should be as easy as

$ sudo passwd root

After that you can use su to log in from a normal user account, or better su -l in order to load the profile. As additional security measure you should make sure that direct login via SSH is disabled; check PermitRootLogin in /etc/ssh/sshd_config.

More details (should mostly be applicable to other distros, too): https://askubuntu.com/a/44419/568304

0

A possible solution, which I do not recomend, due to security reasons, is to delete the password from the root user:

$ sudo passwd -d root

From the passwd(1) man page:

-d

This is a quick way to delete a password for an account. It will set the named account passwordless. Available to root only.

See passwd(1)

Edit

As stated out in trentcl commentary, the solution that I propose won't meet the user requirement.

Instead it will disable the possibility to log in as root. In this case the only way to gain root access will be through sudo. Some Linux distros make root passwordless by default.

1
  • 1
    Passwordless doesn't mean you can log in without a password, it means you can't log in as that user at all. If you do this it just makes sudo the only way to get root access (because the password you type at a sudo prompt is your own, not root's). Some Linux distros make root passwordless by default.
    – trent
    Nov 28, 2019 at 12:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .