English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
# Preface: Why to run tomcat as a non-root user
A serious problem with running tomcat as a root user is that tomcat has root permissions.
This means that any of your page scripts (html/js) have root permissions, so it can easily modify all the files on the hard disk with page scripts!
So it is better not to use root to start tomcat.
# Main text: Running tomcat as a non-root user ## Tomcat installation Omitted... The installation directory of this article is /opt/tomcat8 ## Create user # Create user group dev groupadd dev # Create user tomcat useradd -g dev -s /usr/sbin/nologin tomcat Note:-s /usr/sbin/nologin prohibit this user from logging in. You can also execute after the user is created useradd -g dev usermod -s | --shell /usr/sbin/nologin username ## Tomcat configuration ### Compile and install service daemon # cd /opt/tomcat8/bin/ # Unzip tar vzxf commons-daemon-native.tar.gz # cd /opt/tomcat8/bin/commons-daemon-1.0.15-native-src/unix/ # Configuration and verification before installation ./configure # If $java_home is not configured, specify the JDK directory ./configure --with-java=/opt/jdk_1.7 If you see the following error message, it means that the JAVA_HOME variable has not been set *** Java compilation tools *** checking for JDK location... configure: error: Java Home not defined. Rerun with --with-java=... parameter If you see the following information, you can compile/Installed *** All done *** Now you can issue "make" # Compile/Install make # After executing make, a jsvc file will be generated, copy it to the tomcat's bin directory cp jsvc /opt/tomcat8/bin ### Modify the startup script file vi /opt/tomcat8/bin/daemon.sh Find the following content test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat # Set JAVA_HOME to working JDK or JRE # JAVA_HOME=/opt/jdk-1.6.0.22 Ändern Sie TOMCAT_USER=tomcat, "tomcat" ist der Benutzer, der Tomcat ausführt. In diesem Artikel wurde der Benutzer, den ich erstellt habe, als tomcat verwendet, daher muss dies nicht geändert werden. Entfernen Sie die Anmerkungen vor JAVA_HOME (d.h. das Zeichen '#') und stellen Sie es auf das Verzeichnis der JDK-Eingabe ein(/opt/jdk_1.7)。 ## Ändern Sie die Berechtigungen des Tomcat-Verzeichnisses # Ändern Sie den Besitzer der Datei chown -R tomcat:dev /opt/tomcat8 # Berechtigungen dem Benutzer erteilen chmod a+x /opt/tomcat8/bin/daemon.sh # Anhang: Tomcat-Befehle # Hintergrund ausführen /opt/tomcat/bin/daemon.sh start # Vordergrund ausführen /opt/tomcat/bin/daemon.sh run # Anhalten /opt/tomcat/bin/daemon.sh stop # Erstellen Sie eine symbolische Verknüpfung/Symbolische Verknüpfung ln -s /opt/tomcat8/bin/daemon.sh /etc/init.d/tomcat8 # tomcat8Hinzufügen zu den Systemdiensten chkconfig –-add tomcat8 # Starten/Anhalten service tomcat8 start/stop
Zusammenfassung
Das oben Gesagte ist von mir den Lesern vorgestellt worden, wie ein nicht-root-Benutzer Tomcat unter Linux ausführt. Ich hoffe, es hilft Ihnen weiter. Wenn Sie Fragen haben, hinterlassen Sie mir bitte eine Nachricht!
Erklärung: Der Inhalt dieses Artikels wurde aus dem Internet übernommen und gehört dem Urheber. Der Inhalt wurde von Internetnutzern freiwillig beigesteuert und hochgeladen. Diese Website besitzt keine Eigentumsrechte und hat den Inhalt nicht von Hand bearbeitet. Diese Website übernimmt keine rechtlichen Verantwortlichkeiten. Wenn Sie urheberrechtliche Inhalte bemerken, senden Sie bitte eine E-Mail an: notice#oldtoolbag.com (Bitte ersetzen Sie # durch @, wenn Sie eine E-Mail senden, und geben Sie relevante Beweise an. Sobald die Inhalte überprüft wurden, wird diese Website die beanstandeten urheberrechtlichen Inhalte sofort löschen.)