How to grant a java tool write permission to /var/log?

8,516

Should I run the jar as sudo?

No. Far too dangerous since you could then change about anything to the system and a single misplaced space could remove your whole system.

Or should I give the running user write permissions to that folder? If yes, how?

Yes. The 2 main commands are to change write permissions and change the USER of your log file:

   sudo chmod 664 /var/log/{yourdir}/mylogfile.log
   sudo chown $USER:$USER /var/log/{yourdir}/mylogfile.log

where $USER is your current active user and {yourdir}/ is a directory you defined (mysql and apache for instance use their own directory in /var/log/ instead of filling up /var/log/). It is a slightly better method.

Share:
8,516

Related videos on Youtube

membersound
Author by

membersound

JEE + Frameworks like Spring, Hibernate, JSF, GWT, Vaadin, SOAP, REST.

Updated on September 18, 2022

Comments

  • membersound
    membersound over 1 year

    I'm running a java tool as a command line app using cronjob: java -jar /var/java/-myfile.jar

    By default I'm using logback and write to /var/log/mylogfile.log.

    Problem: the user running the jar has no permissions to write to the /var/log/ folder. That folder has only permissions to `root syslog'.

    Question: should I run the jar as sudo? Or should I give the running user write permissions to that folder? If yes, how?

    • ridgy
      ridgy almost 7 years
      Don't run the .jar as sudo; every mistake (wrong paths e.g.) could destroy your system. As syslog has write access, you might add the user to that group: adduser <user> syslog.
    • membersound
      membersound almost 7 years
      Thanks for you opinion. You might want to add this as an answer, so I could accept it lateron?
  • Hindol
    Hindol over 4 years
    Might be slightly better to actually create a directory within /var/log and change ownership of that directory as this allows the app to create or re-create the log file.
  • Rinzwind
    Rinzwind over 4 years
    I agree :) editted.