Check if a user is root in a java application

前端 未结 7 722
日久生厌
日久生厌 2021-02-08 09:25

How can i verify if a user is root in a java application?

Thanks

7条回答
  •  攒了一身酷
    2021-02-08 10:04

    The best way is to run

     Process p = Runtime.getRuntime.exec("groups `whoaim`"); 
    

    and try to parse string to get group call root. Your JVM process could be run by user not call root but i.e. moderator but this user could be in root group and you have root privileges.

提交回复
热议问题