I want to run the following commands:-
# su - username
$ ssh-keygen -t rsa
enter 3 time to pass null to ssh-keygen options then
$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 0600 ~/.ssh/authorized_keys
$ tar xzf tarpath
$ mv untaredfile ~/somename
on shell terminal but via Java i.e I need to automate these commands,in which username and tarpath will be provided dynamically through gui.
I tried executing it with java Runtime but was not able to get the expected result each time I call
Runtime.getRuntime().exec("somecommand");
it creates a new instance of that command so all previous command doesn't exists in it.Like switching to user.
can anyone suggest me any solution either a custom shell script or through ProcessBuilder.