Using NetworkManager for Ethernet on Ubuntu

If I try to activate a USB Ethernet device with nmtui on Ubuntu, I get this error:

Could not activate connection:
Connection 'USB Ethernet' is not available
 on device eth0 because device is strictly unmanaged
Could not activate connection:
Connection 'USB Ethernet' is not available
on device eth0 because device is strictly unmanaged

And in the logs, I get this error:

Failed to activate 'USB Ethernet': Connection 'USB Ethernet' is not available on device eth0 because device is strictly unmanaged

I googled around a fair bit, but couldn't find out what "strictly unmanaged" meant, or how to change my devices to managed. Some posts suggested that changing the 'ifupdown' managed setting to 'true' could help, but it didn't in my case (I don't have any devices configured in /etc/network/interfaces). After reading a whole bunch of NetworkManager documentation I found that devices can also be marked as unmanaged by a unmanaged-devices line in a NetworkManager keyfile config section... But there's no unmanaged-devices line in my /etc/NetworkManager/ directory at all!

# grep -ri unmanaged-devices /etc/NetworkManager/* || echo "Nothing"
Nothing
#

Well, after paying close attention to the logs it turns out NetworkManager also reads "lib" config files, which live inside /usr/lib/NetworkManager/conf.d/.

Read config: /etc/NetworkManager/NetworkManager.conf (lib: 10-dns-resolved.conf, 10-globally-managed-devices.conf, 20-connectivity-ubuntu.conf, no-mac-addr-change.conf)

/usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf contains the offending unmanaged-devices line. It specifies everything is "strictly unmanaged", other than Wi-Fi, GSM and CDMA devices.

$ cat /usr/lib/NetworkManager/conf.d/10-globally-managed-devices.conf
[keyfile]
unmanaged-devices=*,except:type:wifi,except:type:gsm,except:type:cdma

So finally I have my answer! To get NetworkManager to manage Ethernet devices as well as Wireless ones, the unmanaged-devices line needs to be overridden to include except:type:ethernet. This can easily be done by running the following lines (as root):

# cat <<EOF >/etc/NetworkManager/conf.d/allow-ethernet.conf
[keyfile]
unmanaged-devices=*,except:type:wifi,except:type:gsm,except:type:cdma,except:type:ethernet
EOF
# systemctl reload NetworkManager

Now NetworkManager is happy to manage my USB Ethernet Adapter, and I can use a pretty GUI to change IPs! :D

Also, if you have another type of device you want to manage but don't know what to put after type:, the following command can help:

$ nmcli --pretty --fields GENERAL.DEVICE,GENERAL.TYPE device show
===============================================================================
                              Device details (lo)
===============================================================================
GENERAL.DEVICE:                         lo
-------------------------------------------------------------------------------
GENERAL.TYPE:                           loopback
-------------------------------------------------------------------------------