Ubuntu – Run nmcli as unprivileged user

dbusnetwork-managerpermissionsraspberrypi

I wrote a Python program to switch WiFi connections via the Network Manager dbus interface, which (I believe) is basically equivalent to the nmcli command-line tool. The script (and nmcli) work properly when run by an unprivileged user on my desktop Ubuntu. I'm trying to figure out how the permissions to allow that were set up.

I'm asking because the same commands don't work on Raspbian, so I'd like to track down where the permissions are different. On Raspbian, when I run my script as an unprivileged user, I get this error when I try to read NetworkManager data via dbus:

dbus.exceptions.DBusException: org.freedesktop.NetworkManager.Settings.PermissionDenied: No session found for uid 1000 (unknown)

and, equivalently, when I run nmcli c as an unprivileged user on Raspbian, it doesn't show the connections as it should. Both work properly with sudo.

My attempts so far

I found some old Ubuntu posts that suggest the PolicyKit package is involved, and that I should create a file /etc/polkit-1/localauthority/50-local.d/org.freedesktop.NetworkManager.pkla with these contents:

[Enable NetworkManager]
Identity=unix-group:netdev
Action=org.freedesktop.NetworkManager.*
ResultAny=yes
ResultInactive=yes
ResultActive=yes

That didn't change anything though. (Notes: all other /etc/polkit-1/localauthority subfolders are empty, and the user is part of the netdev group. I'm not sure what else to check.)

I'm very new to dbus and NetworkManager, so I'd appreciate any help understanding how the permissions to send dbus signals are granted, and how I can troubleshoot a missing NetworkManager permission.

Best Answer

"No session found for uid 1000" being solved by reinstalling dbus package.

apt install dbus

then it's important to reboot, as dbus configs gets upgraded only after.