525

I am trying to compile some sources using a makefile. In the makefile there is a bunch of commands that need to be ran as sudo.

When I compile the sources from a terminal all goes fine and the make is paused the first time a sudo command is ran waiting for password. Once I type in the password, make resumes and completes.

But I would like to be able to compile the sources in NetBeans. So, I started a project and showed netbeans where to find the sources, but when I compile the project it gives the error:

sudo: no tty present and no askpass program specified

The first time it hits a sudo command.

I have looked up the issue on the internet and all the solutions I found point to one thing: disabling the password for this user. Since the user in question here is root. I do not want to do that.

Is there any other solution?

feeling_lonely
  • 6,665
  • 4
  • 27
  • 53

30 Answers30

307

Granting the user to use that command without prompting for password should resolve the problem. First open a shell console and type:

sudo visudo

Then edit that file to add to the very end:

username ALL = NOPASSWD: /fullpath/to/command, /fullpath/to/othercommand

eg

john ALL = NOPASSWD: /sbin/poweroff, /sbin/start, /sbin/stop

will allow user john to sudo poweroff, start and stop without being prompted for password.

Look at the bottom of the screen for the keystrokes you need to use in visudo - this is not vi by the way - and exit without saving at the first sign of any problem. Health warning: corrupting this file will have serious consequences, edit with care!

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
nicdaniau
  • 3,356
  • 1
  • 13
  • 10
  • 4
    Yes, the [sudoers man page](http://www.sudo.ws/sudoers.man.html) has opened my eyes to how sudo is actually supposed to be used. – Spencer Williams Apr 30 '15 at 04:36
  • 6
    visudo should open up in whatever EDITOR your environment is configured to use, which very well could be (and should be ^_^) vi. – Matt Styles May 29 '15 at 22:59
  • 9
    Make sure the NOPASSWD mathing line is AFTER any other sudo lines that may match (like %wheel) that does not have the NOPASSWD flag. – anthony Jan 28 '16 at 07:01
  • 49
    i can't "sudo visudo" because I can't sudo in the first place! – Gubatron Sep 23 '16 at 06:46
  • 11
    Consider adding a file to /etc/sudoers.d and leaving the visudo file untouched. – xlttj Mar 01 '17 at 09:58
  • 1
    how to do this programmatically? – Alexander Mills May 08 '17 at 23:03
  • 1
    But of course `NOPASSWD` is insecure in many settings. Resolving the lack of a tty as addressed in the other answers seems much wiser. – nealmcb Sep 10 '17 at 14:09
  • 1
    This is not a solution, this is a workaround. The only thing that helped me was an answer below (about adding the `-S` flag to `sudo`). You should target the problem and passwords are not the problem here. The error is the problem – Victor Mar 13 '19 at 08:00
212

Try:

  1. Use NOPASSWD line for all commands, I mean:

    jenkins ALL=(ALL) NOPASSWD: ALL
    
  2. Put the line after all other lines in the sudoers file.

That worked for me (Ubuntu 14.04).

Kalle Richter
  • 8,008
  • 26
  • 77
  • 177
Fatemeh Jabbari
  • 2,215
  • 1
  • 11
  • 3
  • 18
    I first added the line after other user configurations, but it only worked when placed as absolutely last line in file on lubuntu 14.04.1. – user77115 Feb 24 '15 at 08:01
  • The second part was the solution I was what I was needing. A existing configuration line (for wheel group) also matched my sudo command but without the NOPASSWD: entry. Placing my new line after it gave it the priority, allowing no password use for the specific command I needed. – anthony Jan 28 '16 at 06:58
  • 6
    As @user77115 had mentioned, this only worked if you placed it as the last line in the sudoers file, even with Ubuntu 16.04. As a side note, giving sudo permissions to jenkins for all commands is a pretty large security concern. Consider wrapping your jenkins scripts and only giving access to specific commands such as: `jenkins ALL=(ALL) NOPASSWD: /var/lib/jenkins/wrapper_script` – ivandov Jun 15 '16 at 20:30
  • `jenkins` is just a user name? It must be user name of user from host machine? What if user name on host machine matches user name from remote server? – mrgloom May 02 '17 at 14:28
  • this is jenkins specific, looks like https://stackoverflow.com/a/22651598/1041319 is more generic solution. – arntg Jun 05 '17 at 22:20
  • Does anybode know why I have to allow `ALL` commands instead of just the specific command (I want to allow) in the case of a Jenkins node? – Lars Bilke Feb 02 '18 at 13:27
  • Worked also on Ubuntu 18.04 for me !! – Guy Avraham Dec 05 '18 at 09:43
  • I've never had to put it at the end. There must be something else in the default file that is reverting the entry unless it's at the end. – Andrew T Finnell May 27 '19 at 16:53
  • I replaced "jenkins" with my username for Ubuntu Mate, and it fixed my issue. – ConcernedHobbit Jul 09 '19 at 13:48
  • 2. Put the line after all other lines in the sudoers file. - this solved my problem – naut92 Apr 14 '20 at 11:31
  • I replaced jenkins with my username and it works well. Ubuntu 18 – Deepak Pandey Jun 19 '20 at 12:34
  • I downvoted as this essentially removes all security or "oh wait, did I intend to run that". Honestly, it's fixing a papercut with a sledgehammer. – J. Gwinner Feb 18 '22 at 23:16
  • @LarsBilke and whoever might stumble across this. Just don't do this. This removes any security and you could just run jenkins as root as well. And Jenkins is so to speak... very common and good target for attackers, who will later wreak havoc on your machine after getting root permissions. Establish which scripts Jenkins needs to run and only allow those. – Dominik Szymański Sep 17 '22 at 17:21
197

Try:

ssh -t remotehost "sudo <cmd>"

This will remove the above errors.

kenorb
  • 155,785
  • 88
  • 678
  • 743
user262129
  • 2,111
  • 2
  • 12
  • 6
  • 10
    `-t Force pseudo-tty allocation. This can be used to execute arbitrary screen-based programs on a remote machine` see also: [sudo-no-tty-present-and-no-askpass-program-specified](http://askubuntu.com/questions/281742/sudo-no-tty-present-and-no-askpass-program-specified) Also `sudo -A` allows setting a `sudo` askpass program, but I only see GUIs. Does anyone one know an askpass to allow `ssh remotehost sudo -A askpass` ? – here Apr 12 '14 at 07:15
  • 2
    Correction, The `-A` for `sudo` does not take arguments and instead requires environment `SUDO_ASKPASS` or a `sudo.conf` So `ssh remotehost sudo -A command` would still work. Still curious about a terminal based askpass program. – here Apr 12 '14 at 09:57
  • 11
    this doesn't work for me (presumably because I'm calling ssh from a script), giving me the error `Pseudo-terminal will not be allocated because stdin is not a terminal.` :( – knocte Jul 17 '16 at 10:02
  • 1
    This does not answer the question. – bschlueter Dec 02 '17 at 23:41
171

After all alternatives, I found:

sudo -S <cmd>

The -S (stdin) option causes sudo to read the password from the standard input instead of the terminal device.

Source

Above command still needs password to be entered. To remove entering password manually, in cases like jenkins, this command works:

echo <password> | sudo -S <cmd> 
Heemanshu Bhalla
  • 3,603
  • 1
  • 27
  • 53
VingtCent
  • 1,874
  • 1
  • 9
  • 10
  • 1
    This seems fixing my issue. But is there any side effect by using this command? – Xiaodong Qi Oct 10 '16 at 19:39
  • 4
    `sudo -S `- `true` just happens to be a dummy command that returns an exit code of 0 (`false` is a command that returns 1). Thank you, this is the one true answer, since all others expect "sudo" to work! – Adam Plocher Oct 23 '16 at 16:44
  • 1
    -S: Write the prompt to the standard error and read the password from the standard input instead of using the terminal device. The password must be followed by a newline character. – fileinsert Mar 29 '17 at 19:44
  • This works right away, and might get sudo working until a timeout, but doesn't address whatever underlying problems might exist, and the problem can come back. – nealmcb Sep 10 '17 at 14:00
  • I don't know if its working but its showing `Password:` then nothing happens. I cant type in the password. – KD.S.T. May 11 '18 at 05:17
  • I would recommend https://stackoverflow.com/a/22651598/3930114 above as by using this method I can see my password on the terminal – Aditya Oct 19 '18 at 21:49
  • @Heemanshu, In my project I need to write some content to text file on linux sftp server, So I am using the same command as you suggested above, but I am getting an error saying permission denied. eg. echo Testpwd | sudo -s echo hi user1 >> PathOf TheFile But following command is working fine. echo Testpwd | sudo -s mkdir PathOf TheFile/file1.txt So I am not getting that if it is working with mkdir then why not with echo? – Dreamer Apr 04 '19 at 15:02
  • @Dreamer https://stackoverflow.com/questions/82256/how-do-i-use-sudo-to-redirect-output-to-a-location-i-dont-have-permission-to-wr – Falmarri May 02 '19 at 03:29
  • I tried this in a GitHub action and it didn't seem to work :( – J. Gwinner Feb 18 '22 at 23:16
49

sudo by default will read the password from the attached terminal. Your problem is that there is no terminal attached when it is run from the netbeans console. So you have to use an alternative way to enter the password: that is called the askpass program.

The askpass program is not a particular program, but any program that can ask for a password. For example in my system x11-ssh-askpass works fine.

In order to do that you have to specify what program to use, either with the environment variable SUDO_ASKPASS or in the sudo.conf file (see man sudo for details).

You can force sudo to use the askpass program by using the option -A. By default it will use it only if there is not an attached terminal.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
  • Current solution requires a gui. What askpass program works on terminal. – here Apr 12 '14 at 07:19
  • @here: Well... if you run ssh from a terminal, it will ask for a password directly, you don't need anything special... Or are you asking about requesting the password from a different terminal than the one that will run the ssh session? – rodrigo Apr 12 '14 at 09:27
  • 1
    ahh now I see that `-A` does not take arguments. `-A` requires environment `SUDO_ASKPASS` or a `sudo.conf` file. In that case, `ssh host "export SUDO_ASKPASS=askpass;sudo -A cat /etc/passwd"` would still work with a terminal based askpass, however @chandru is far more concise below with `ssh -t ...` – here Apr 12 '14 at 09:53
  • There are some cavats with using -A. First, if -A is used and SUDO_ASKPASS has not been set you will get an error. Second, when -A is used ssh will not use cached credentials, it will always request a password. – anthony Oct 22 '19 at 03:45
  • As a adendum you may like to look at my notes on password input programs... http://www.ict.griffith.edu.au/anthony/info/crypto/passwd_input.txt – anthony Oct 22 '19 at 03:46
  • Thrid, sudo does not 'wait' on the password reader. As such the program will become a zombie until the sudo command exits! – anthony Oct 22 '19 at 03:50
27

Try this one:

echo '' | sudo -S my_command
sNICkerssss
  • 6,312
  • 1
  • 24
  • 16
27

For Ubuntu 16.04 users

There is a file you have to read with:

cat /etc/sudoers.d/README

Placing a file with mode 0440 in /etc/sudoers.d/myuser with following content:

myuser  ALL=(ALL) NOPASSWD: ALL

Should fix the issue.

Do not forget to:

chmod 0440 /etc/sudoers.d/myuser
Vasili Pascal
  • 3,102
  • 1
  • 27
  • 21
  • 1
    Nice. Cleaner solution than the popular one. – Paul Praet Oct 01 '17 at 08:35
  • 7
    Do not follow this blindly. I created a new file in /etc/sudoers.d as described here and ended up not being able to use sudo anymore.. had to delete the file through recovery mode. – Stian Feb 04 '18 at 16:34
18

Login into your linux. Fire following commands. Be careful, as editing sudoer is a risky proposition.

$ sudo visudo

Once vi editor opens make the following changes:

  1. Comment out Defaults requiretty

    # Defaults    requiretty
    
  2. Go to the end of the file and add

    jenkins ALL=(ALL) NOPASSWD: ALL
    
Matt Raines
  • 4,149
  • 8
  • 31
  • 34
Susil Parida
  • 382
  • 2
  • 4
16

If by any chance you came here because you can't sudo inside the Ubuntu that comes with Windows10

  1. Edit the /etc/hosts file from Windows (with Notepad), it'll be located at: %localappdata\lxss\rootfs\etc, add 127.0.0.1 WINDOWS8, this will get rid of the first error that it can't find the host.

  2. To get rid of the no tty present error, always do sudo -S <command>

Gubatron
  • 6,222
  • 5
  • 35
  • 37
  • 2
    Thanks for providing an answer for people who came here for a reason unrelated to question description, but matching question title. +1 – Jayant Bhawal Nov 12 '16 at 17:05
  • 5
    [DO NOT, under ANY circumstances, create and/or modify Linux files using Windows apps, tools, scripts, consoles, etc.](https://blogs.msdn.microsoft.com/commandline/2016/11/17/do-not-change-linux-files-using-windows-apps-and-tools/) – nikeee May 07 '17 at 13:25
13

This worked for me:

echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

where your user is "myuser"

for a Docker image, that would just be:

RUN echo "myuser ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
12

In Jenkins:

echo '<your-password>' | sudo -S command

Eg:-

echo '******' | sudo -S service nginx restart

You can use Mask Password Plugin to hide your password

Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
Ankit Gupta
  • 129
  • 1
  • 3
8

Make sure the command you're sudoing is part of your PATH.

If you have a single (or multi, but not ALL) command sudoers entry, you'll get the sudo: no tty present and no askpass program specified when the command is not part of your path (and the full path is not specified).

You can fix it by either adding the command to your PATH or invoking it with an absolute path, i.e.

sudo /usr/sbin/ipset

Instead of

sudo ipset

omribahumi
  • 2,011
  • 1
  • 17
  • 19
  • 1
    This is actually forked for me. in `sudoers` `%sitd ALL=(lamparna) NOPASSWD: /usr/bin/git_push_to_lamparna.sh, /usr/bin/git` and using `sudo -u lamparna git push --mirror ssh://lamparna@REDMINE/home/lamparna/repos/git/jine/lamparna.git` in git post-update hook return `no tty`, but using `sudo -u lamparna /usr/bin/git push --mirror ssh://lamparna@REDMINE/home/lamparna/repos/git/jine/lamparna.git` work without password. – Foton Sep 16 '15 at 07:16
6

Command sudo fails as it is trying to prompt on root password and there is no pseudo-tty allocated (as it's part of the script).

You need to either log-in as root to run this command or set-up the following rules in your /etc/sudoers (or: sudo visudo):

# Members of the admin group may gain root privileges.
%admin  ALL=(ALL) NOPASSWD:ALL

Then make sure that your user belongs to admin group (or wheel).

Ideally (safer) it would be to limit root privileges only to specific commands which can be specified as %admin ALL=(ALL) NOPASSWD:/path/to/program

kenorb
  • 155,785
  • 88
  • 678
  • 743
  • I know, that's much safer way to do. Although, I wrote the following command in `sudoers` file `apache ALL = (ALL) NOPASSWD:/usr/share/apache-tomcat-7.0.61/bin/startup.sh` but it doesn't work for me. it gives the following error `sudo: >>> /etc/sudoers: syntax error near line 120 <<< sudo: parse error in /etc/sudoers near line 120 sudo: no valid sudoers sources found, quitting sudo: unable to initialize policy plugin` – Muaaz Khalid Jun 13 '15 at 10:57
  • 1
    BTW, it works well `apache ALL=(ALL) NOPASSWD: ALL` but a security risk. :) – Muaaz Khalid Jun 13 '15 at 10:58
6

I think I can help someone with my case.

First, I changed the user setting in /etc/sudoers referring to above answer. But It still didn't work.

myuser   ALL=(ALL) NOPASSWD: ALL
%mygroup  ALL=(ALL:ALL) ALL

In my case, myuser was in the mygroup.

And I didn't need groups. So, deleted that line.

(Shouldn't delete that line like me, just marking the comment.)

myuser   ALL=(ALL) NOPASSWD: ALL

It works!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
kihoon han
  • 119
  • 2
  • 2
2

Running shell scripts that have contain sudo commands in them from jenkins might not run as expected. To fix this, follow along

Simple steps:

  1. On ubuntu based systems, run " $ sudo visudo "

  2. this will open /etc/sudoers file.

  3. If your jenkins user is already in that file, then modify to look like this:

jenkins ALL=(ALL) NOPASSWD: ALL

  1. save the file

  2. Relaunch your jenkins job

  3. you shouldnt see that error message again :)

Chandra Pal
  • 239
  • 2
  • 2
2

I'm not sure if this is a more recent change, but I just had this problem and sudo -S worked for me.

ATLief
  • 428
  • 4
  • 15
1

This error may also arise when you are trying to run a terminal command (that requires root password) from some non-shell script, eg sudo ls (in backticks) from a Ruby program. In this case, you can use Expect utility (http://en.wikipedia.org/wiki/Expect) or its alternatives.
For example, in Ruby to execute sudo ls without getting sudo: no tty present and no askpass program specified, you can run this:

require 'ruby_expect'

exp = RubyExpect::Expect.spawn('sudo ls', :debug => true)
exp.procedure do
    each do
        expect "[sudo] password for _your_username_:" do
            send _your_password_
        end
    end
end

[this uses one of the alternatives to Expect TCL extension: ruby_expect gem].

Evgenia Karunus
  • 10,715
  • 5
  • 56
  • 70
1

For the reference, in case someone else encounter the same issue, I was stuck during a good hour with this error which should not happen since I was using the NOPASSWD parameter.

What I did NOT know was that sudo may raise the exact same error message when there is no tty and the command the user try to launch is not part of the allowed command in the /etc/sudoers file.

Here a simplified example of my file content with my issue:

bguser ALL = NOPASSWD: \
    command_a arg_a, \
    command_b arg_b \
    command_c arg_c

When bguser will try to launch "sudo command_b arg_b" without any tty (bguser being used for some daemon), then he will encounter the error "no tty present and no askpass program specified".

Why?

Because a comma is missing at the end of line in the /etc/sudoers file...

(I even wonder if this is an expected behavior and not a bug in sudo since the correct error message for such case shoud be "Sorry, user bguser is not allowed to execute etc.")

WhiteWinterWolf
  • 239
  • 2
  • 10
1

I was getting this error because I had limited my user to only a single executable 'systemctl' and had misconfigured the visudo file.

Here's what I had:

jenkins ALL=NOPASSWD: systemctl

However, you need to include the full path to the executable, even if it is on your path by default, for example:

jenkins ALL=NOPASSWD: /bin/systemctl

This allows my jenkins user to restart services but not have full root access

dannrob
  • 1,061
  • 9
  • 10
1

If you add this line to your /etc/sudoers (via visudo) it will fix this problem without having to disable entering your password and when an alias for sudo -S won't work (scripts calling sudo):

Defaults visiblepw

Of course read the manual yourself to understand it, but I think for my use case of running in an LXD container via lxc exec instance -- /bin/bash its pretty safe since it isn't printing the password over a network.

salotz
  • 429
  • 4
  • 20
1

Using pipeline:

echo your_pswd | sudo -S your_cmd

Using here-document:

sudo -S cmd <<eof
pwd
eof
#remember to put the above two lines without "any" indentations.

Open a terminal to ask password (whichever works):

gnome-terminal -e "sudo cmd"
xterm -e "sudo cmd"
Himanshu Tanwar
  • 198
  • 1
  • 11
1

I faced this issue when working on an Ubuntu 20.04 server.

I was trying to run a sudo command from a remote machine to deploy an app to the server. However when I run the command I get the error:

sudo: no tty present and no askpass program specified
The remote script failed with exit code 1

Here's how I fixed it:

The issue is caused by executing a sudo command which tries to request for a password, but sudo does not have access to a tty to prompt the user for a passphrase. As it can’t find a tty, sudo falls back to an askpass method but can’t find an askpass command configured, so the sudo command fails.

To fix this you need to be able to run sudo for that specific user with no password requirements. The no password requirements is configured in the /etc/sudoers file. To configure it run either of the commands below:

sudo nano /etc/sudoers

OR

sudo visudo

Note: This opens the /etc/sudoers file using your default editor.

Next, Add the following line at the bottom of the file:

# Allow members to run all commands without a password
my_user ALL=(ALL) NOPASSWD:ALL

Note: Replace my_user with your actual user

If you want the user to run specific commands you can specify them

# Allow members to run specific commands without a password
my_user ALL=(ALL) NOPASSWD:/bin/myCommand

OR

# Allow members to run specific commands without a password
my_user ALL=(ALL) NOPASSWD: /bin/myCommand, /bin/myCommand, /bin/myCommand

Save the changes and exit the file.

For more help, read the resource in this link: sudo: no tty present and no askpass program specified

That's all.

I hope this helps

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
1

The solution to the problem is

If you came across this issue anywhere else apart from the Jenkins instance follow this from the 2nd step. The first step is for the user who is having issue with the Jenkins instance.

Go to Jenkins instance of Google Cloud Console. Enter the commands sudo su

visudo -f /etc/sudoers

Add following line at the end

jenkins ALL= NOPASSWD: ALL

Checkout here to understand the rootcause of this issue

Engineer
  • 21
  • 2
0

No one told what could cause this error, in case of migration from one host to another, remember about checking hostname in sudoers file:

So this is my /etc/sudoers config

User_Alias      POWERUSER = user_name
Cmnd_Alias SKILL = /root/bin/sudo_auth_wrapper.sh
POWERUSER hostname=(root:root) NOPASSWD: SKILL

if it doesn't match

uname -a
Linux other_hostname 3.10.17 #1 SMP Wed Oct 23 16:28:33 CDT 2013 x86_64 Intel(R) Core(TM) i3-4130T CPU @ 2.90GHz GenuineIntel GNU/Linux

it will pop up this error:

no tty present and no askpass program specified

Abc Xyz
  • 1,184
  • 12
  • 13
0

Other options, not based on NOPASSWD:

  • Start Netbeans with root privilege ((sudo netbeans) or similar) which will presumably fork the build process with root and thus sudo will automatically succeed.
  • Make the operations you need to do suexec -- make them owned by root, and set mode to 4755. (This will of course let any user on the machine run them.) That way, they don't need sudo at all.
  • Creating virtual hard disk files with bootsectors shouldn't need sudo at all. Files are just files, and bootsectors are just data. Even the virtual machine shouldn't necessarily need root, unless you do advanced device forwarding.
Jon Watte
  • 6,579
  • 4
  • 53
  • 63
0

I had the same error message when I was trying to mount sshfs which required sudo : the command is something like this :

sshfs -o sftp_server="/usr/bin/sudo /usr/lib/openssh/sftp-server" user@my.server.tld:/var/www /mnt/sshfs/www

by adding the option -o debug

sshfs -o debug -o sftp_server="/usr/bin/sudo /usr/lib/openssh/sftp-server" user@my.server.tld:/var/www /mnt/sshfs/www

I had the same message of this question :

sudo: no tty present and no askpass program specified

So by reading others answer I became to make a file in /etc/sudoer.d/user on my.server.tld with :

user ALL=NOPASSWD: /usr/lib/openssh/sftp-server

and now I able to mount the drive without giving too much extra right to my user.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
JOduMonT
  • 171
  • 6
0

Although this question is old, it is still relevant for my more or less up-to-date system. After enabling debug mode of sudo (Debug sudo /var/log/sudo_debug all@info in /etc/sudo.conf) I was pointed to /dev: "/dev is world writable". So you might need to check the tty file permissions, especially those of the directory where the tty/pts node resides in.

u_Ltd.
  • 544
  • 1
  • 4
  • 9
0

I was able to get this done but please make sure to follow the steps properly. This is for the anyone who is getting import errors.

Step1: Check if files and folders have got execute permission issue. Linux user use:

chmod 777 filename

Step2: Check which user has the permission to execute it.

Step3: open terminal type this command.

sudo visudo

add this lines to the code below

www-data ALL=(ALL) NOPASSWD:ALL
nobody ALL=(ALL) NOPASSWD:/ALL

this is to grant permission to execute the script and allow it to use all the libraries. The user generally is 'nobody' or 'www-data'.

now edit your code as

echo shell_exec('sudo -u the_user_of_the_file python your_file_name.py 2>&1');

go to terminal to check if the process is running type this there...

ps aux | grep python

this will output all the process running in python.

Add Ons: use the below code to check the users in your system

cut -d: -f1 /etc/passwd

Thank You!

3rdi
  • 475
  • 4
  • 12
  • 2
    `chmod 777` compromises your system's security; it lets even completely untrusted users like `nobody` run an executable that you're then running with `sudo`. It should **never** be recommended, and any system it was run on should be considered compromised and untrustable. – Charles Duffy Nov 24 '20 at 20:34
  • 2
    -1. Do NOT EVER use chmod 777 on an executable that is meant to be used with `sudo`. This completely destroys the purpose of `sudo` and root access itself, since as said by @CharlesDuffy EVERYONE will be able to access it without using sudo – LukeSavefrogs Jul 27 '21 at 06:17
  • To be clear, `777` doesn't just let everyone _access_ the executable, it also lets everyone _change_ the executable. Replace it with something with a virus or worm, for example? Sure, it's set world-writable, why not?! – Charles Duffy Jul 27 '21 at 13:22
0

1 open /etc/sudoers

type sudo vi /etc/sudoers. This will open your file in edit mode.

2 Add/Modify linux user

Look for the entry for Linux user. Modify as below if found or add a new line.

<USERNAME> ALL=(ALL) NOPASSWD: ALL

3 Save and Exit from edit mode

Maulik Kakadiya
  • 1,467
  • 1
  • 21
  • 31
0

Below actions work for on ubuntu20

  1. edit /etc/sudoers
visudo

or

vi /etc/sudoers
  1. add below content
userName   ALL=(ALL) NOPASSWD: ALL
%sudo   ALL=(ALL:ALL) NOPASSWD:ALL
xiaojueguan
  • 870
  • 10
  • 19
  • 3
    This is really bad answer and not should be used. This grants access to `sudo` in your system without password. – Mateech Aug 06 '21 at 13:21
  • Mateech: given that you're probably only seeing this issue in the first place because it's a chroot environment, i think it's fine. – Owl Apr 25 '22 at 13:40