Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  4] [ 0]  / answers: 1 / hits: 3881  / 3 Years ago, fri, july 30, 2021, 11:23:06

Sorry for my bad English, but I'm really trying to be better.
Ok. I've created a new command/alias(changejava) on Ubuntu 12.04, and I need to skip "sudo password" only when I write "$changejava".
If I write "$changejava" using terminal, Ubuntu show me what can I do. I just need to press 0, 1 or 2. But if I press anything, terminal says:




"update-alternatives: to use /usr/lib/jvm/java-6-sun/jre/bin/java to provide /usr/bin/java (java).
update-alternatives: error: Could not create file '/var/lib/dpkg/alternatives/java.dpkg-tmp': Denied. "



If I try "$sudo changejava", I have: "Type jessegaspar password", and the magic happens. Without "sudo", does not happen.
I tried to edit /etc/sudoers with:




%sudo ALL=NOPASSWD: ALL



...However all users will have access to the total permission "sudo".
:/ :/



Thanks.


More From » java

 Answers
1

First I want to reiterate that you do not need to change the system-wide default Java runtime in order to run a program using a non-default Java runtime.



For example, Eclipse and NetBeans have configuration files where you can specify which Java runtime it should use.



Also typical of Java applications is to honor the $JAVA_HOME environment variable. So at the shell, just run JAVA_HOME=/usr/lib/jvm/java-6-sun/ foo and JAVA_HOME=/usr/lib/jvm/java-7-oracle/ bar for applications foo and bar. You can even put this in a script so you don't have to type it each time.






Since you are focused on changing the system-wide default Java runtime, the Ubuntu Community documentation on sudo is one place to read: https://help.ubuntu.com/community/Sudoers



The manpage (ie man sudoers) is another: http://www.sudo.ws/sudo/sudoers.man.html



You are correct in stating that you do not want %sudo ALL=NOPASSWD: ALL in your sudoers file. Instead try something like this:



    jessegaspar caelum-sala1-9 = (root) NOPASSWD:/usr/local/bin/changejava


This may be more restrictive than you really want, but it is an example. It is probably good practice to list the full path to the command, but that may not be the path to your script on your system.


[#35987] Sunday, August 1, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
allally

Total Points: 487
Total Questions: 106
Total Answers: 110

Location: Laos
Member since Sun, Jul 3, 2022
2 Years ago
;