By default, Geoserver uses a data directory under webapps/. This is, of course, ridiculous for persistence purposes, as on each undeploy all data are lost. To configure an external data directory able to survive undeployments, you need to edit WEB-INF/web.xml and set the value of the context parameter GEOSERVER_DATA_DIR to point to that directory. E.g.:
<context-param> <param-name>GEOSERVER_DATA_DIR</param-name> <param-value>/mnt/some-other-disk/geoserver-data</param-value> </context-param>
Purportedly setting and exporting the environment variable GEOSERVER_DATA_DIR on the shell from which Tomcat is launched has the same effect but my experience was to the contrary.
After trying various suggestions on how to restore the root password in Geoserver, in the end, what did the trick was deleting the entire data/security directory at which point the default settings were restored.
In January 2025 while working with a GeoServer I had installed locally for my own development where I had simply copied over the data/ directory of a production GeoServer (after having erased, first, the local data directory) I encountered problems in logout and, I belive, login which I addressed by editing file webapps/geoserver/data/global.xml and:
As a matter of fact, I don't think the second part was necessary.
provenance (tried January 2025)
Login via master password has been disabled by default back in 2018, see GEOS-8928: Disable master password Admin GUI login by default
In order to enable root login, take the following steps:
It should be noted that the effect of the above instructions results in a change in the contents of file security/masterpw/default/config.xml which is to be found in GeoServer' data directory. Specifically, the following element is added:
<loginEnabled>true</loginEnabled>
If you have lost the ability to get in as admin, you can enable the root login by going to the data directory, get into “security/masterpw/default”, open “config.xml” and switch loginEnabled to true. Then probably restart (not 100% sure it’s needed) and you should be able to login.
NB: the below instructions assume that Java 11 is already installed (I had the OpenJDK version).
Contrary to representations on this page which declare that "GeoServer [2.26.x] requires a newer version of Tomcat (7.0.65 or later) that implements Servlet 3 [...]" I nevertheless encountered this problem which shows that GeoServer 2.26.2 is incompatible with Tomcat 10.1.34. As advised in the currently accepted solution I therefore installed Tomcat 9.0.98 using the procedure described below and found GeoServer to run fine with it.
CATALINA_HOME=/media/hddb/software/apache-tomcat/apache-tomcat-9.0.98/ CATALINA_BASE=/media/hddb/software/apache-tomcat/apache-tomcat-9.0.98/ JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64/