# Preface: Why use a non-root user to run Tomcat
Root user started Tomcat there is a serious problem, that is, Tomcat has root privileges.
This means that any one of your page scripts (HTML/JS) has root privileges, so you can easily modify the files on your entire hard drive with a page script!
So It's best not to use root to start Tomcat.
# Body: Non-root user running Tomcat
# # Tomcat Installation
Slightly... The installation directory for this article is/OPT/TOMCAT8
# # Create User
# Create a user group Dev Groupadd Dev # Create user tomcatuseradd-g dev-s/usr/sbin/nologin Tomcat
Description:-s/usr/sbin/nologin prevents the user from logging on.
You can also execute after the user is created
Useradd-g Dev
Usermod-s | --shell/usr/sbin/nologin username
# # Tomcat Configuration
# # # Compile and install the 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/# pre-installation configuration and Verification ./Configure# if $java_home is not configured, the JDK directory needs to be specified ./configure--with-java=/opt/jdk_1.7
If the following error message appears, the Java_home variable is not set
Java Compilation Tools * * * for JDK location ... Configure:error:Java Home not defined. Rerun with--with-java= ... parameter
If you see the following information, you can compile/install the
All do ** *"make"
# Compile/install Make # when you do make, a jsvc file is generated and copied to the Tomcat bin directory CP Jsvc/opt/tomcat8/bin
# # # Modify the startup script file
vi/opt/tomcat8/bin/daemon.sh
Find the following:
" . $TOMCAT _user " = . && tomcat_user=TOMCAT# Set java_home to working JDK or JRE# java_home=/ opt/jdk-1.6.0.22
Modify Tomcat_user=tomcat, "Tomcat" is the user who is running Tomcat, the user created by this article is Tomcat, so there is no need to modify it.
Remove the comment (that is, "#") before Java_home and set it to the directory where the JDK is located (/opt/jdk_1.7).
# # Change the Tomcat directory permissions
# Change file owner chown-r tomcat:dev/opt/tomcat8# give user the right to execute chmod a+x/opt/tomcat8/bin /daemon.sh
# attached: Tomcat command
# background Run /opt/tomcat/bin/daemon.sh start# foreground run /opt/tomcat/bin/daemon.sh Run # stop /opt/tomcat/bin/daemon.sh stop
# Create a symbolic link/soft connect ln-s/opt/tomcat8/bin/daemon.sh/etc/init.d/tomcat8# TOMCAT8 Add to System service chkconfig–-addtomcat8# start/stop service tomcat8 start/stop
Linux-running Tomcat for non-root users