Reputation: 405
I am trying to run a unix command from Java using java.lang.Process class. How can we pass a specific user so that the command executes with the permissions of that specific user ? I don't want to execute the command with a superuser.
Upvotes: 0
Views: 224
Reputation: 9941
You could start a login
command first and then input credentials into it.
I would guess that starting su - [USER]
should do the trick.
After reading through apropos user
I came across the pkexec
command which should do what you need.
Upvotes: 1
Reputation: 8597
You could use a ssh session, that logs with the user you know its password and run a specific command.
E.g. using java shell JSch
or
or
I found a good thread here by the way: Jsch or SSHJ or Ganymed SSH-2?
Upvotes: 2
Reputation: 136022
You can run a new shell and execute commands which will switch to another user and then run the programm
Upvotes: 0