• We did not send an email asking for donations - please read this post.

Command Question

mechi

Member
Joined
Dec 28, 2019
Messages
57
Reaction score
22
Credits
70
What does $ sudo chmod a+rw -R /var/lib/vnstat/* do? I came across it while trying to figure out how to get vnstat to record bandwidth usage for my broadband connection. Since yesterday it keeps telling me "Not enough data available yet". I think for some reason it's not writing the bandwidth to file because when I use the command vnstat -l it will show the bandwidth as a webpage loads but once it's loaded the bandwidth goes to 0
 
Last edited:


captain-sensible

Well-Known Member
Joined
Jun 14, 2019
Messages
2,913
Reaction score
1,970
Credits
18,126
well i can at a glance break some of it down.

sudo is giving equivalent of root rights

chmod is giving permission command

from top of my head a+ rw will be read write permission to root
-R means reciprocal permission to everything (*) outside to in , that lives at /var/lib/vnstat/
 

JasKinasis

Well-Known Member
Joined
Apr 25, 2017
Messages
1,568
Reaction score
2,230
Credits
11,595
What that is doing is recursively applying read/write permissions for ALL users to everything in /var/lib/vnstat/

That will mean that literally ANYBODY logged into your system will be able to read and write to the files in /var/lib/vnstat/
Security-wise, this would be a BAD thing to do if you ask me.

If this is a multi-user system where there are several users - changing the permissions like this would mean that ANY other user could tamper with the files in /var/lib/vnstat/.

So from what I can see, this suggestion is a bad/hacky way of going about things!

However, if it's only you using the system - you probably could get away with using this little permissions hack to get around the problem. But I'm sure there's probably a better way to do it!

For example, this page tells you how to install vnstat on a debian system, but it does not require messing with any permissions:

What Linux distro are you using?
 
OP
M

mechi

Member
Joined
Dec 28, 2019
Messages
57
Reaction score
22
Credits
70
Thanks, I solved my problem with this command:
sudo chown -R vnstat:vnstat /var/lib/vnstat

Is it safer? I got it from the unbuntu website. I think it means that ownership of the file has been switched to vnstat, so now it's able to write to the file and display bandwidth use.
 

Rob

Administrator
Staff member
Joined
Oct 27, 2011
Messages
925
Reaction score
1,778
Credits
1,201
Hey there - by using the chown command, you changed the ownership and the group owners of all files under /var/lib/vnstat to the vnstat user .. that's how they should be.

Also, if you want to change the permissions back to normal:
/var/lib/vnstat wants to be 755
The files under there (one for each interface) want to be 644.

Code:
[rob lib ]$ ls -ld vnstat
drwxr-xr-x 2 vnstat vnstat 4096 Jan 20 18:25 vnstat
[rob lib ]$ ls -l vnstat
total 12
-rw-r--r-- 1 vnstat vnstat 2792 Feb 14 08:56 docker0
-rw-r--r-- 1 vnstat vnstat 2792 Feb 14 08:56 enp38s0f1
-rw-r--r-- 1 vnstat vnstat 2792 Feb 14 08:56 wlp0s20f3
 
OP
M

mechi

Member
Joined
Dec 28, 2019
Messages
57
Reaction score
22
Credits
70
Thanks much, I'm glad I looked around before attempting the first fix I came across.
 
$100 Digital Ocean Credit
Get a free VM to test out Linux!

Linux.org Hosting Donations
Consider making a donation

Members online


Top