I found that on my OSX system I have "weird" setup. Java reads my user name as "root" instead of my actual user name. Turns out the code I used uses System.getPropery("user.name") call. So, I made up stand-alone snipped (I save it under test.java) which prints java system user.name property and my UNIX user name environment:
class UserName {
public static void main(String[] args) {
String name;
name = System.getProperty("user.name");
System.out.println("user.name="+name);
name = System.getenv("USER");
System.out.println("USER="+name);
}
}
if I compile it as javac test.java and then run it (under my account, not root one) as java UserName it prints the following:
user.name=root
USER=vk
My question is where/how java sets user.name and why it is set to root instead of my actual UNIX name. I'm not java expert and don't really know internals of System.getProperty API.
The second question is it possible to change this settings somehow in UNIX environment that it will read properly my user name.
Finally may be my environment or java configuration is broken and there is some hidden file (properties) which should be fixed.
The problem was resolved by turning off setuid bit in java executable. Thanks goes to David Conrad for correct tip. For the reference:
ls -l /usr/bin/java
-rwsr-xr-x ... /usr/bin/java
sudo chmod -s /usr/bin/java
lrwxr-xr-x ... /usr/bin/java
and after that everything was reported properly.
You are running java with sudo or after you run su command and become root. (Maybe MacOS by default run your commands as root since your user in an administrators group).
Same output is also obtained on Linux (CentOS) when run after su command with root privileges.
user.name=root
USER=jdiver
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With