I have a file /var/logs/apache2/error.log
. And every time I boot, Its file permission is changed to default (unwritable) by the system. So, i have to run chmod
command every time i boot-up. How to change it's file permission permanently.
3 Answers
Log files are usually created by logrotate. The apache logfiles definition is stored on /etc/logrotate.d/apache2
The file looks like this in one of my servers:
/var/log/apache2/*.log {
weekly
missingok
rotate 52
compress
delaycompress
notifempty
create 640 root adm
sharedscripts
postrotate
if [ -f "`. /etc/apache2/envvars ; echo ${APACHE_PID_FILE:-/var/run/apache2.pid}`" ]; then
/etc/init.d/apache2 reload > /dev/null
fi
endscript
}
If you look at the create option, the values after the keyword are the permissions, user and group. Just edit your file and change this values.
I'm guessing anacron
is running logrotate
at boot time.
If so, try editing the configuration file /etc/logrotate.d/apache2
, and change
create 640 root adm
to whatever you prefer, e.g.
create 666 root adm
But other than the apache2
service, what else needs to write to this file?
If this is on a server, it's probably a bad idea to make the file world writable. For example, if somebody breaks in to your system, they can remove the log entries that would help you find the problem.
If you want read access, it might be better to add yourself to the adm
group, e.g.
gpasswd -a `whoami` adm
This would also help if you really do need write access, e.g.
create 660 root adm
would be sufficient.
-
The usual reason is letting some customers or some software (traffic analysis, monitoring) access to the logs without granting it extra privileges that could be a security risk. Mar 30, 2011 at 10:48
-
Read access, probably OK. But the poster said write access was required too.– MikelMar 30, 2011 at 10:51
-
As per the discussion in comments, for the purpose the OP is trying to achieve (looking at a simple subset of logs for a specific purpose), this may be an appropriate alternative solution:
Tail will let you look at the last lines of a file
Grep lets you search through a file for instances you want to find
Both are available as part of Unix/Linux and should be part of your essential toolkit.
grep
andtail
programs or soft packages?