I have to add multiple AP and passwords to multiple Linux machines and need to automate that. Recently I've write a bash script to write configs to files in /etc/NetworkManager/system-connections/ like the files that were generated by the system. But without success.


I have a file AP.txt with MAC addresses, SSID and password:


and multiple machines:


I would like to make a script to add those AP to my computers automaticaly, so that every machine can connect automatically to the nearest AP.


Assuming you have root ssh keys setup and locally generated templates, stat with this;

for HOST in $HOSTS ; do
    scp wifi-templates/* $HOST:/etc/NetworkManager/system-connections/
    ssh $HOST 'U=$(ls -1 /home/ | head -n 1); perl -pi -e "s/(permissions=user:)you(:;)/$1'$U'$2/g" /etc/NetworkManager/system-connections/*'


while read L ; do
    SSID=$(echo $L | cut -d ";" -f 1)
       N=$(echo $L | cut -d ";" -f 2)
    PASS=$(echo $L | cut -d ";" -f 3)
    cp template $N
    perl -pe 's/SSID/'$SSID'/g;s/PASS/'$PASS'/g' $N
done < AP.txt

*This code is for demonstration only (untested and may require tweaking for it to work) Please read the man page of each command before use;

  • Thank you for your help, but I need to do the template, need help with that. I tried to manualy insert a template to /etc/NetworkManager/system-connections/ but when near an AP that I added it doesnt connect to them. – molotow Mar 27 '18 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.