1

I'm trying to run Motion app on a Linux box.

For various security reasons, I'd rather run it as regular user than sudo. However, when I run "service motion start" without the sudo in front, it says:

chown: changing ownership of `/var/run/motion': Operation not permitted 

Googling doesn't seem to yield any results relevant to this situation.

Anton Dozortsev
  • 224
  • 1
  • 5
  • 14
Uzumaki Naruto
  • 157
  • 1
  • 7

3 Answers3

3

When I've installed motion in the past it's been done so that it's running as its own designated user, typically motion. I'd suggest doing the same thing here for your installation as well.

EDIT #1

The OP asked how this was done. I explained that if you install the motion package via either Debian/Ubuntu or Fedodra repos the installation would be done so that everything you needed to run motion as another user, motion in my cases, was done out of the box by default.

If you look at the files that would typically get installed with motion, a SYSV init script is often provided, /etc/init.d/motion. Within this script, on Ubuntu, is a section like this:

case "$1" in
  start)
    if check_daemon_enabled ; then
        if ! [ -d /var/run/motion ]; then
                mkdir /var/run/motion
        fi
        chown motion:motion /var/run/motion

    log_daemon_msg "Starting $DESC" "$NAME" 
if start-stop-daemon --start --oknodo --exec $DAEMON -b --chuid motion ; then
            log_end_msg 0
        else
            log_end_msg 1
            RET=1
        fi
    fi
    ;;

If you look at the start-stop-daemon line you'll notice that when motion is started ($DAEMON) the switch --chuid motion is passed, which will run the motion daemon process as user motion.

Something similar is done on my Fedora & CentOS systems as well in their corresponding /etc/init.d scripts for motion.

slm
  • 363,520
  • 117
  • 767
  • 871
2

It is trying to change owner of the file /var/run/motion and has insufficient permission.

If the file exists, you can try and change the owner yourself

sudo chown username /var/run/motion

It may then go forward and hit a new issue.

It would be better to reconfigure from default values for motion and then locate these sort of files within your /home/username structure or create a directory you own below /var/run for your runtime application files.

X Tian
  • 10,413
  • 2
  • 33
  • 48
1

The standard way to handle this is to make a group and assign the user(s) who are going to use the program to the group. Then you chown all of the directories to the new group and chmod them to allow members of the group to read and write there.

groupadd motion_users
vipw  # to update groups for user(s)
chown -R motion_users /var/run/motion  # and anything else
chmod g+rwx /var/run/motion

Now login as the user and it should work as long as the device permissions are there. Note you have to log out and back in for groups to be added to a user.

Sean Perry
  • 331
  • 1
  • 6