Check if a user is root in a java application

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

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

Thanks

7条回答
  •  清酒与你
    2021-02-08 09:52

    Process p = Runtime.getRuntime().exec("id -u")
    

    Keep in mind that the "root" user on a system may not be called root (although it's rare to change it), and it's also possible to alias it to another username. If the current user is root-like, the output will be 0.

提交回复
热议问题