Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java program (class > .jar) as a Unix shell (in place of sh/bash)?

I'm looking to run a Java program (compiled class > .jar file) as my Unix shell. Basically, I don't want sh or bash to be involved, as then users could shell out/suspend out of my Java program and access the unix shell.

Is this possible?

Do I need to use jail/chroot?

Is it as simple as editing /etc/shells and putting the java -jar ... command in there?

Alternatively, if I must use sh/bash, can I auto-exit the shell when my java/vm expires or is unloaded (so nobody can escape the Java app into the bash/sh shell itself)?

like image 773
IPvFletch Avatar asked Nov 01 '22 05:11

IPvFletch


1 Answers

Step one: Create a wrapper shell script /usr/bin/myjavashell:

#!/bin/sh
exec /usr/bin/java -jar /usr/local/whatever/file.jar

Step two: Make it executable: chmod +x /usr/bin/myjavashell

Step three: Add /usr/bin/myjavashell to /etc/shells.

Step four: Set this as the user's login shell with chsh -s /usr/bin/myjavashell youruser.

Optional step five : In /etc/ssh/sshd_config, disable any additional options you don't want the user to be able to do that doesn't require a shell, like tcp forwarding:

Match User youruser
AllowTcpForwarding False
like image 50
that other guy Avatar answered Nov 09 '22 11:11

that other guy