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)?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With