0

on this siite >How do I edit the /etc/hosts file? i would ask my question but i dont have permission. strange, because now i have to open a new question, why ? thats was not the question.

i try to make a starter on my desktop wich opens a file with sudo, directly. in terminal it works like "sudo leafpad /etc/hosts" with a charme. but if i put the same command in a starter, nothing happens.

the target is with one click to put new hp in it.

why its ok in the terminal but not in the starter ???????? also not possibel to make a shortcut. why?

thanks for answers

6
  • What problem are you encountering that makes it necessary for you to frequently edit /etc/hosts? That's unusual.
    – user535733
    Apr 28 '20 at 20:35
  • so i can block all websites with advertising and pop-ups and other redirecting sites. if they are like "0.0.0.0 netgames.com" so they are blocked. and there are always newones see> vitux.com/linux-hosts-file
    – tiger1001
    Apr 28 '20 at 20:39
  • thanks but i need a litle help to understand. i am poweruser, not programer, sorry. a script is a text file with the command in - i'm right?? it have to be a special ending like .sh ? or only making "executable"? for my understanding, why the command works in terminal but not in a shortcut??
    – tiger1001
    Apr 28 '20 at 20:51
  • it may have to do with the sudo command needing the password so my solution may not actually work without setting up your user as a passwordless sudo user. I think because it uses the password when you try to shortcut it, it doesn't have a place for a password so it fails ... there is a program that Ubuntu discontinued called gksu which could be used for a GUI style shortcut and would open a password dialog box. gksu still works but finding it is more difficult and not in the repos anymore. If my solution doesn't work and you want to set up for passwordless sudo let me know
    – John Orion
    Apr 28 '20 at 21:17
  • ok actually I deleted my answer because I was playing around and found that what I was saying here was right ... its because sudo in terminal has a password that can be entered but in a GUI situation it doesn't get that input so it doesn't function .. I used your "sudo leafpad /etc/hosts" and it works fine as a "launcher" which is what my version calls the "shortcut" the reason is because as I said .. if I type in sudo in terminal it doesn't ask me for a password so when I make a "shortcut" using sudo .. it doesn't ask for a password and succeeds
    – John Orion
    Apr 28 '20 at 21:27
0

Not a solution but it should be a workaround

Open Terminal and open your FileManager using sudo Ex. sudo thunar &

The "&" at the end will allow the Terminal to continue to run and not be "locked" with the file managers process just in case we need to type another command.

Ok now that you have a File Manager running as root we can do some adding of files. Navigate to /etc/sudoers.d and create a document / plain text. Name the file your user name... for this example I will use orion for the user name. Ok now in the /etc/sudoers.d directory I have a file called orion. Click (double click or whatever) to open the file and enter the following:

%orion ALL=(ALL) NOPASSWD: ALL

save the file and that should be it. You will no longer need a password in terminal when using sudo and you will now be able to create that "shortcut" using sudo leafpad /etc/hosts

I will say that this will make your system less secure and not something that should be done on a "public machine" but I'm lazy and hate typing my password all the time :)

4
  • i thought it must be easy and i only dont know the way, but . . . . . . thank you all and thanks for a solution, even i like it more when some works have to be with a pw. @orion > and thats the problem ? because linux cant show a thing to write in the pw ???? strange, because if i open synaptic its prompt a gui to put the pw in.
    – tiger1001
    Jun 8 at 14:04
  • issue is (from what I'm understanding)"sudo leafpad /etc/hosts" works in terminal because it has a password prompt. The command prompt does not have a popup window so when you try to use it as a shortcut it hangs because its looking for a password that it has no way of getting. Synaptic gives you a prompt because its not launched by sudo its launched by .. I believe.. pkexec synaptic and it has to have a policy attached. This was confusing to me when trying to make a program run as root so I defaulted to the above process. When sudoers.d is set up like this ..
    – John Orion
    Jun 9 at 18:37
  • if you run the sudo leafpad /etc/hosts in terminal it will just launch without prompting you for a password which is why "now" it will work as a shortcut because when the shortcut "runs terminal sort of" it doesn't fail because the password prompt is no longer active.
    – John Orion
    Jun 9 at 18:39
  • If you want it to prompt for a password in a "gui" you will have to look into pkexec and I hope I got that name correct ... look for alternatives for gksu and I think you will find more on the pkexec and policies.
    – John Orion
    Jun 9 at 18:47

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.