Linux Commands from Java

Is it possible to execute linux commands using java? I am trying to create a web servlet so ftp users can change their passwords without access to ssh. I would like to execute the following commands:

# adduser -s /sbin/nologin clientA -d /home/mainclient/clientA # passwd clientA # cd /home/mainclient; chgrp -R mainclient clientA # cd /home/mainclient/clientA; chmod 770 . 
+6
java linux
source share
5 answers

Mark it .

However, doing what you are talking about is a way outside the specification, and I would not recommend it. To make it work, you either start your application server as root, or use some other mechanism to give the user the application server to work as permission to execute these privileged commands. One little flogging somewhere, and you β€œowned”.

+9
source share

Using:

 Runtime.getRuntim().exec("Command"); 

where Command is the command line you want to execute.

+5
source share

If you call these commands from Java, be sure to pack several commands in one shell script. This will ease the challenge.

+1
source share

Java RunTime object has exec methods to run commands in a separate process

0
source share
0
source share

All Articles