(Solved) Cannot open mailbox /var/mail/user: Permission denied error in Linux

The Linux mailx command gives Cannot open mailbox /var/mail/user: Permission denied error when the user is not part of the mail group or /var/mail/user does not exist Below is the exact error,

$ mailx
Cannot open mailbox /var/mail/imaginelinux: Permission denied
No mail for imaginelinux

This is the way  you can resolve it, 

First, you need to check the group of the current user. Use the groups command to display all groups for the current user as shown below.

$ groups 
imaginelinux adm cdrom sudo dip plugdev lpadmin lxd sambashare

You can see the user imaginelinux is not part of the mail group. So you have to add.

Now, add the user to the mail group using the adduser command.

$ sudo adduser imaginelinux mail
[sudo] password for imaginelinux: 
Adding user `imaginelinux' to group `mail' ...
Adding user imaginelinux to group mail
Done.

Run groups command again to see if user is added to the group.

$ groups
imaginelinux adm mail cdrom sudo dip plugdev lpadmin lxd sambashare

Next, check if the/var/mail/imaginelinux directory exists and it has proper permission. If the directory does not exist the run the following command.

$ mail imaginelinux@localhost 
Cc: 
Subject: hi
Null message body; hope that's ok
$

Now run mailx command and now you can see the folder is created and there is email as well.

$ mailx
"/var/mail/imaginelinux": 1 message 1 new
>N 1 imaginelinux Wed Sep 2 23:51 12/417 hi
?

That’s it. Above steps should help you to resolve permission denied error while using mailx command.

I hope you found this small tip helpful. Please share and subscribe.

Reference – askubuntu

Scroll to Top