Search code examples
linuxtomcatterminalcentosvi

Editing tomcat-users.xml in CentOS 7 Linux


I am trying to edit tomcat-users.xml in Tomcat 8, using the terminal of CentOS 7 Linux. I typed su - to use the terminal as the root account.

I then typed in vi $CATALINA_HOME/conf/tomcat-users.xml, but the result is that vi opens in the window with the contents of tomcat-users.xml in read-only mode, and there seems to be no way out of vi except to close the window, losing all the terminal history.

I also navigated to the physical location of tomcat-users.xml and opened up the file using Gedit, but Gedit will not allow me to save the file. How can I edit tomcat-users.xml?


Solution

  • When you open vi, you are in command mode. Type i to place yourself in insert mode. make your edits then when you are finished use the escape key to toggle back to command mode. Then type :q! to exit without saving or ZZ to save and close. I believe barjomet is correct that as root, :wq! will allow you to write to a read only file.

    you might want to investigate why the file permissions are read only. See who owns the file and what the permissions are by using the ls command with the -l option Example: ls -l /some/folder/somefile.xml

    change the permissions (if you know what you're doing) by using chmod command and change owner by using the chown command (be careful, don't mess up the permissions and create a security flaw, I can't help with that as I don't know tomcat)