Modifying the system files to skip asking for password can be dangerous and also can lead to unexpected behaviour and problems.
So the way without Modifying anything it to use
sudo su
this will make you login to the super user and you can do anything you want without asking for password and the good thing is when you close the terminal and open a new terminal , the new one will be normal as before without the need to undo the change in any files
Top comments (3)
That's not making
sudo
not ask for a password, it's logging in as a different user (root in this case).You can edit your
sudoers
file withvisudo
(don't worry, it doesn't have to usevi
, it'll use whatever you have configured in yourEDITOR
environment variable, just don't edit the file directly).Each line has a user and two parameters. The last one is usually
ALL
but can be changed toNOPASSWD:ALL
and that user will magically be able to usesudo
everywhere without putting in a password.There aren't that many times you'd really want to do it, though. The most common way for sudo to be set up, it'll prompt you for your password once and then "remember" it until you've been idle for a certain period of time. If you want to be able to use
sudo
in scripts where you can't physically type your password in, the best solution is to do something else instead! Typically, unattended scripts like that are managed by your init system or cron. The init system runs as a privileged user and delegates things, and cron can be configure on a per-user basis or system-wide as root anyway."this will make you login to the super user and you can do anything you want without asking for password and the good thing is when you close the terminal and open a new terminal , the new one will be normal as before without the need to undo the change in any files"
I personally made a bot that would start and restart your vpn and network services to reset your ip address , it was in python , executing commands with
sudo
asked me password everytime the the script didservice whatever restart
, so usingsudo su
and then running the script will not make you type the password until you exit out of that terminal (which in most cases is enough)
"make sudo not ask for password" is the post title, and that's not what it's about.
A similar example could be "visit the shops and cafes without wearing a mask" but the post turns out to be about using Amazon to get things delivered. Similar, but critically different.
sudo
doesn't need you to exit the session. It has a number of benefits, such as auditing who ran a command and being able to see in your history what you ran as root. You also don't need to close the terminal to exit fromsu
, you can typeexit
or hit ctrl-D to log out of that session.sudo
(by default) doesn't prompt you every time for your credentials, it prompts you after five minutes of inactivity. Another thing you could do, if you really wanted to bypass securty, is to usesetuid
to make your script run as root regardless of who ran it. Then you wouldn't ever need to put in your password at all.