Why am I getting a Permission Denied Here?

$ sudo chown asterisk:asterisk /etc/asterisk ; sudo chmod 664 /etc/asterisk
$ sudo -u asterisk vim /etc/asterisk/modules.conf

Despite of issuing a chown and a chmod

modules.conf is “Permission-Denied”

How about sudo chown -R asterisk:asterisk /etc/asterisk ?

Permission still Denied

  1. What does “ls -l /etc/asterisk/modules.conf” output?

  2. Can the asterisk user edit any other files?

Antony.

  1. What does “ls -l /etc/asterisk/modules.conf” output?
    ls: cannot access /etc/asterisk/modules.conf : Permission denied
  2. Can the asterisk user edit any other files?
    same Permission Denied for logger.conf too
    $ sudo -u asterisk vim /etc/asterisk/logger.conf

ls: cannot access /etc/asterisk/modules.conf : Permission denied

I think we need to take a few steps back and start asking about this machine,
if you’re getting “permission denied” for a simple ls command.

  1. What operating system & version is it?

  2. How did you install Asterisk?

  3. Does Asterisk start / can it process calls?

Antony.

  1. What operating system & version is it?
    CentOS 7 Minimal
  2. How did you install Asterisk?
    Three more commands and Asterisk is installed:
    $ make # this will take several minutes to complete # (depending on the speed of your system)
    $ sudo make install # you must run this with escalated privileges
    $ sudo make config # this too
  3. Does Asterisk start / can it process calls?
    image

Who is astmin?

Antony.

Let’s see whether user asterisk exists:
grep asterisk /etc/passwd

Same for the group:
grep asterisk /etc/group

While the installation is taking place, set the root password, and also create a user
named astmin. Make the astmin user an administrator.

The following commands can be typed from the command line, or added to a simple
shell script and run that way.
sudo yum -y update &&
sudo yum -y install epel-release &&
sudo yum -y install python-pip &&
sudo yum -y install vim wget dnf&&
sudo pip install alembic ansible &&
sudo pip install --upgrade pip &&
sudo mkdir /etc/ansible &&
sudo chown astmin:astmin /etc/ansible &&
sudo echo “[starfish]” >> /etc/ansible/hosts &&
sudo echo “localhost ansible_connection=local” >> /etc/ansible/hosts &&
mkdir -p ~/ansible/playbooks

We’ve installed Ansible simply because it’s a quick and easy way to get all the dependencies
met. We’ve written a playbook to perform the following operations:

  1. Install dnf, vim, wget, and MySQL-python.
  2. Install the MySQL community-edition repository.
  3. Install mysql-server.
  4. Tweak some variables in the mysql-server installation.
  5. Start the mysql-server daemon.
  6. Modify some MySQL credentials (create users, set passwords).
  7. Create a MySQL database/schema for Asterisk to use.
  8. Apply some security best practices (remove anonymous user, test database, etc.).
  9. Create asterisk user.
    10. Create astmin user.
  10. Install dependencies for ODBC.
  11. Install some diagnostic tools.
  12. Tweak the firewall to allow SIP and RTP traffic.
  13. Edit some ODBC config files.
    This can all be done manually, but it’s just a lot of typing, and Ansible is really good at
    streamlining this process.
    Create an Ansible playbook in the file ~/ansible/playbooks/starfish.yml.
  • user:
    name: astmin
    groups: asterisk,wheel
    state: present

Reboot the system.
Once the boot is complete, log back in as the astmin user, and temporarily set SELinux
to Permissive (it will revert to Enforcing after each boot, so until we’ve sorted
out the SELinux portion of the install, this has to happen on every boot):
$ sudo setenforce Permissive
$ sudo sestatus
This should show Current mode: permissive
Verify that Asterisk is running with the following command:
$ ps -ef | grep asterisk

Start from scratch and replace every astmin with asterisk, or replace all asterisk strings with astmin.

I’d restart from scratch as this would be a normal installation. BTW, where did this recipe come from?

Then sudo -u astmin vim /etc/asterisk/modules.conf should work. Of course you need to undo any previous ownership changes.

If the user/group didn’t exist, wouldn’t that show a different error on the
sudo command?

Antony.

“While the installation is taking place, set the root password, and also
create a user named astmin. Make the astmin user an administrator.”

Where does this instruction come from?

What documentation are you following to install Asterisk?

Antony.

No, it means that you mixed some recipes. You should better know what asterisk and astmin mean here.

“While the installation is taking place, set the root password, and also
create a user named astmin. Make the astmin user an administrator.”

Where does this instruction come from?
28 | Chapter 3: Installing Asterisk

What documentation are you following to install Asterisk?

So, out of interest, which version of Asterisk have you installed?

Antony.

asterisk-16.30.0