I'm writing this as systemd seems to be getting stronger and is replacing initd little by little. Now if like me you have one or more Linux systems that do not run a desktop environment. You may find yourself using a few apps that normally require a GUI to be configured. NetworkManager is one of those, but does allow you to use the CLI (nmcli).
Here's how:
Assuming you already have everything installed :)
systemctl enable NetworkManager
Will start networkmanager at boot.
nmcli d
will list all interfaces controlled by networkmanager.
To add a connection eg wifi
nmcli c add ifname wlp5s0 type wifi ssid <your ssid>
This will create the file
/etc/NetworkManager/system-connections/wifi-wlp5s0
Which will contain the skeleton config (non working)
[connection] id=<your ssid> uuid=b083dd98-f1e0-4bc5-bff6-56c4a1b56e2f interface-name=wlp5s0 type=wifi
[wifi] ssid=1027251N mode=infrastructure
We now need to configure the connection. (additions highlighted)
[connection] id=<your ssid> uuid=b083dd98-f1e0-4bc5-bff6-56c4a1b56e2f type=wifi
[wifi] ssid=1027251N mode=infrastructure mac-address=00:23:14:B7:57:A0 security=wifi-security
[wifi-security] key-mgmt=wpa-psk auth-alg=open psk=<your ultra secure key>
executing
nmcli c reload
will/should now connect you :)