How to Solve Cannot open mailbox /var/mail/user: Permission denied for Mailx Command 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/atechtown: Permission denied
No mail for atechtown

Steps to solve Cannot open mailbox /var/mail/user: Permission denied

1. First, check the group of the user

$ groups 
atechtown adm cdrom sudo dip plugdev lpadmin lxd sambashare

You can see here atechtown user is not part of the mail group. So you ned to add.

2. Add user to mail group using adduser command.

$ sudo adduser atechtown mail
[sudo] password for atechtown: 
Adding user `atechtown' to group `mail' ...
Adding user atechtown to group mail
Done.
$ groups
atechtown adm mail cdrom sudo dip plugdev lpadmin lxd sambashare

3. Now check if /var/mail/atechtown directory exists and it has proper permission. If the directory does not exist and run the following command.

$ mail [email protected] 
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/atechtown": 1 message 1 new
>N 1 atechtown Wed Sep 2 23:51 12/417 hi
?

Summary

Just add the user to the mail group and send a dummy email to the user to resolve Cannot open mailbox /var/mail/user: Permission denied. No mail for user error for mailx command in Linux.

Reference – Cannot open mailbox /var/mail/USER: Permission denied No mail for USER

Share This: