Running Asterisk As a Non-root User
By default, Asterisk runs as the root user, and while we don’t have any hard data, our own experiences lead us to conclude that the vast majority of Asterisk systems are run in this default state. From a security perspective, this represents an unacceptable risk―strangely, one which most of us seem willing to take.
Running Asterisk as non-root is not terribly hard to achieve, but it requires a few extra steps, and debugging it can be frustrating if you do not understand how Linux permissions work. However, from a security perspective it is well worth the effort.
We’re going to run Asterisk as the user asterisk, so we need to create that user on our system first. The following commands will be run as root. We’ll tell you when to switch and use the asterisk user that we’re about to create:
#adduser -c "Asterisk PBX" asterisk#passwd asterisk
Now
that you’ve created the asterisk user, let’s switch
to that user, with which we’ll perform the rest of the commands. Once we
su to the asterisk user,[141] we can download a copy of Asterisk via SVN, FTP or WGET,
and then compile and install. We’re going to grab a copy of Asterisk
from the SVN repository in the following example.
Note
1.4.5 is the current release version at the time of this writing, but it won’t be by the time you read this, so check the Asterisk web site for the latest version. In other words, don’t just type 1.4.5 whenever you see us refer to it. Find out what is current and use that instead. ...