I would like to start tomcat (Web Server) as a privileged user, and then bring it back to an unprivileged user once it has started. Is there a way to do this programatically, or in general with Linux?
Thanks.
To change ownership of files or directories we use chown command in the Linux system. This command is also available in the IBM i operating system. The chgrp command is also used to change only the group ownership of the file in the Linux system.
Users, processes, and files in Linux. Launch processes and own files. A process is a program (executable file) that the kernel has loaded into main memory and runs. Have owners; by default, the user who creates the file owns it.
Change owner (chown) is a command in Linux that effectively changes the owner of a file. Files in Linux have one owner and one group assigned, as part of a consistent system for data administration in this operating system environment.
To change the owner of a symbolic link, use the -h option. Otherwise, the ownership of the linked file will be changed. The following image shows how symbolic links behave when -h is omitted. The owner and group of the symbolic link remain intact.
The underlying system call that you need is setuid(2)
, but it's not exposed by any of the Java APIs.
It's not hard to write a JNI wrapper that would give access to it though, although even then you'd need to find a suitable place in the Tomcat startup code to invoke setuid
after the bind(2)
calls have been made (those being the ones that normally require the root privileges).
As recommended by geocar you could use authbind
so that Tomcat never needs to run as root at all.
Alternatively, as you've presumably got root access on the server in question, just run Tomcat on a non-privileged port and then use iptables
tricks to forward inbound requests from the privileged port to the one that Tomcat is actually listening on. See this SO post for info on how to do this.
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