Skip to main content

Tomcat Security and User Accounts

Security and User Accounts

  • If we need to access the Tomcat WebApplications then we need to setup some user accounts.
  • For this we need to edit the conf/tomcat-users.xml
  • At the bottom of this file we can find some roles and user accounts
  • Let us add some new roles and users now
    • Adding tomcat,manager, manager-gui, admin-gui roles
     <role rolename="tomcat"/>
     <role rolename="manager"/>
     <role rolename="manager-gui"/>
     <role rolename="admin-gui"/>
    
    • Adding admintom user
     <user username="admintom" password="s3cret" roles="manager,manager-gui,admin-gui"/>
    
  • Now setting up your Hostname / IP to your server instead of localhost
    • Open conf/server.xml and edit the following lines to add your Hostname
     Find the line starts with Engine and change the value of defaultHost
     <Engine name="Catalina" defaultHost="dev02.linux-library.com">
     
     Find the line starts with Host change the value of name to your hostname same as above
     <Host name="dev02.linux-library.com"  appBase="webapps"
    
  • If you want to access the tomcat manager from other than your local machine then you need to allow those IP ranges
    • To allow IPs to access manager edit webapps/manager/META-INF/context.xml file
    NOTE: If you want to access the app from a host of Class-A IP then you should add 10.\d+.\d+.\d+ to the allow directive That should look like below. I have allowed Class-A as well as Class-C ranges
     allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1|10\.\d+\.\d+\.\d+|192\.168\.1\.\d+" />
    
    • In the same way you can allow access to you hostmanager too.
    • Open webapps/host-manager/META-INF/context.xml and edit same as above

Comments

Popular posts from this blog

Troubleshooting Tomcat using Catalina log

Troubleshooting Tomcat using Catalina log We can get the  catalina  logs in  $CATALINA_HOME/logs Here we'll have a  catalina.out We can see some huge info in that log file. If we want to what exactly happens since the start of tomcat then we need to log that into a new file. By default we have log rotation enabled on this logs. For now let us stop tomcat and nullify the catalina.out file and then start tomcat to have some new info in the catalina.out # service tomcat stop # cd $CATALINA_HOME/logs # :> catalina.out (or) cat /dev/null > catalina.out # ll catalina.out -rw-r----- 1 root root 0 Feb 18 16:19 catalina.out # service tomcat start # ll catalina.out -rw-r----- 1 root root 17341 Feb 18 16:21 catalina.out We can see the log being written after the start of tomcat. Now we can notice the instance giving some information about the starting of tomcat, about the configuration for the startup, path of the servlet instance for which the log is re...

Managing tomcat application

Tomcat is a servlet application which is ready to use after download. There is no need of installing this application. We can directly start or stop it from the bin directory.  So in such case we should go to the bin directory in the CATALINA_HOME or else we need to use the startup script along with its absolute path. And the same is needed to shut it down. We can use the below script to manage the tomcat application and we neither need to go to the CATALINA_HOME nor to use the absolute path. All we need to do is to change the permissions to make it executable and copy that to /sbin and /etc/init.d/ directories. If we copy this into /etc/init.d/ then also we need to mention the absolute path but we can easily memorize it as we know all the startup scripts exists there. But if we copy that into /sbin then there is absolutely no need of mentioning the path of the file. We can use this like below: # tomcat start|stop|restart|status #!/bin/bash # Author : Arjun S...

Apache Tomcat 8 Application Server Introduction

Apache Tomcat 8 Application Server Introduction Apache Tomcat, often referred to as Tomcat Server, is an open-source Java Servlet Container developed by the Apache Software Foundation (ASF). Tomcat implements several Java EE specifications including Java Servlet, JavaServer Pages (JSP), Java EL, and WebSocket, and provides a "pure Java" HTTP web server environment in which Java code can run. Tomcat is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation, released under the Apache License 2.0 license, and is open-source software. Below are the components of Tomcat: 1. Catalina Catalina is Tomcat's servlet container. Catalina implements Sun Microsystems's specifications for servlet and JavaServer Pages (JSP). In Tomcat, a Realm element represents a "database" of usernames, passwords, and roles (similar to Unix groups) assigned to those users. Different implementations of Realm al...