1

I made a script to set/unset the proxy setting for when I switch between work and home. The script works perfectly and now I wanna run it every time automatically when I login so I put it in my .profile (like : source ~/bin/proxyscript.sh).

This works when I was using Ubuntu Gnome and during login I get a terminal and it asked for the sudo password. Since version 16.10 I installed a clean version of Ubuntu Unity and now I get the error message "sudo: no tty present and no askpass program specified" when I login.

In the script I do something like : sudo service cntlm stop sudo sed ..... /etc/cntlm.conf sudo service. cntlm start

I already looked at the /etc/sudoers file and added the following without a good result: Defaults !/usr/bin/sed !requiretty Defaults !/usr/sbin/service !requiretty

root ALL=(ALL:ALL) ALL jeroen ALL=NOPASSWD: /bin/sed, /usr/sbin/service

I don't know what I now can try to fix this problem. Anyone any idea ?

Thanks.

  • you should not use sudo in a script – mchid Nov 1 '16 at 8:31
1

You should not use sudo in a script. You can use policykit instead of sudo in your script:

#!/bin/bash
pkexec env DISPLAY=:0 XAUTHORITY=/home/$USER/.Xauthority service cntlm stop & sed whatever is missing here
pkexec env DISPLAY=:0 XAUTHORITY=/home/$USER/.Xauthority service cntlm start

or, better yet . . . just do the sed command first and then restart the service so that you only need to enter a password twice

#!/bin/bash
pkexec env DISPLAY=:0 XAUTHORITY=/home/$USER/.Xauthority sed 'some sed stuff' 
pkexec env DISPLAY=:0 XAUTHORITY=/home/$USER/.Xauthority service cntlm restart

Also, if you still have problems, I would suggest running the script from "startup applications" instead of from your .profile file. You can search for "startup applications in your dash"

  • I'm going to replace sudo with what you say. But do I than also need to keep my changes to the /etc/sudoers file ? – JdKock Nov 1 '16 at 10:43
  • @JdKock No, I would recommend changing the sudoers file back to normal. It's probably not good security to have stuff like sed set to execute without permission like that. As for the popup, this is a normal message. – mchid Nov 6 '16 at 4:04
  • Oke I changed the sudoers file back to normal and take the popup as it is. Thanks. – JdKock Nov 8 '16 at 7:46
0

I changed my script and replaced the sudo for :

pkexec env DISPLAY=:0 XAUTHORITY=/home/$USER/.Xauthority sed 'some sed stuff'

This worked, thanks mchild !

Now I get a popup to enter my password. With the message : Authentication is needed to run '/usr/bin/env' as the super user

But is it also possible without to enter a password ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.