I want to run Apache Tomcat on Ubuntu 18 as the (by me created) user tomcat
.
I am not using the Ubuntu default Tomcat but instead directly downloaded the tar.gz package from the Tomcat homepage.
I have installed it in /opt
.
For security reasons I want to run the tomcat a user tomcat
which I created in the following way:
sudo useradd -r -s /bin/false tomcat
Now, I would like to start tomcat using the following script:
#!/bin/bash
/bin/su -s /bin/bash -c "/opt/tomcat/bin/startup.sh" tomcat
When I run this script I get the following output:
ubuntu@server-8x32:/opt/tomcat/bin$ ./start-tomcat.sh
Password:
I did not specify a password and since this script is also called from some other automatically executed script I cannot provide a password each time.
So my question is: How do I start Apache Tomcat as the user tomcat
without being prompt to enter a password?
Best Answer
Create the
tomcat
group and this file at/etc/systemd/system/tomcat.service
with the contents:Start the service with
That will run the service as
tomcat
.