在 Debian 上配置 Tomcat 用户,通常是指两种情况之一:
下面分别说明。
Debian 上通过 apt 安装的 Tomcat(如 tomcat9、tomcat10)默认已创建系统用户 tomcat。
grep tomcat /etc/passwd
通常类似:
tomcat:x:110:114:Tomcat servlet engine,,,:/nonexistent:/usr/sbin/nologin
编辑 systemd 服务文件:
sudo systemctl edit tomcat9
添加:
[Service]
User=tomcat
Group=tomcat
然后重启:
sudo systemctl restart tomcat9
一般不建议手动改,除非你有特殊权限需求。
路径通常为:
/etc/tomcat9/tomcat-users.xml
(tomcat10 为 /etc/tomcat10/tomcat-users.xml)
<tomcat-users>
<role rolename="manager-gui"/>
<role rolename="admin-gui"/>
<user username="admin"
password="StrongPassword"
roles="manager-gui,admin-gui"/>
</tomcat-users>
默认 Tomcat 禁止远程访问 Manager。
编辑:
/etc/tomcat9/Catalina/localhost/manager.xml
内容:
<Context privileged="true"
antiResourceLocking="false"
docBase="${catalina.home}/webapps/manager">
<Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="^.*$" />
</Context>
生产环境建议限制 IP,而不是
^.*$
sudo systemctl restart tomcat9
manager.xml直接修改 tomcat-users.xml 并重启。
admin 作为用户名如果你能说明:
我可以给你更精确的配置示例。