On my Ubuntu-based distro (Linux Lite), how to auto delete all network connections, disable Wi-Fi and networking as part of booting process?
1
vote
1
answer
354
views
My end goal here is to have no saved network connections, no enabled Wi-Fi or networking each time I boot up my computer, so that I have to go through a sequence of steps in order to access internet. The purpose is to moderate my sceen behavior.
My current way is through creating a script that uses 'nmcli' and run at startup using crontab's @reboot. But It's not working.
Here is the script
#!/bin/bash
# this script disables wifi and networking
echo 'Deleting all existing connections...'
# nmcli is a command-line interface for networkmanager
# 'nmcli connection delete' -> simply deletes a connection by ID, UUID or others
# we use 'nmcli connection show' along with some filter to extract UUIDs for all conections
# TODO enable deletion of a particular connection
#connections_list=$(nmcli connection show | grep -oP '\s(\S+-\S+-\S+-\S+-\S+)\s')
#for connection in "$connections_list"; do
#nmcli connection show "$connection"
#if (($? != 0)); then
#echo "something went wrong while deleting connection $connection" >&2
#exit 1
#fi
#done
nmcli connection delete $(nmcli connection show | grep -oP '\s(\S+-\S+-\S+-\S+-\S+)\s')
if [[ $? -ne 0 ]]; then
echo 'shit happens while deleting connections' >&1
exit 1
fi
echo 'All connections were deleted! now, you will have to type SSID and password again'
echo
echo 'Disabling Wi-Fi...'
if ! nmcli radio wifi off; then
echo 'nmcli, command disabling wifi, is not satisfied for some reason' >&2
exit 1
fi
echo 'Wi-Fi is disabled.'
echo
echo 'Disabling networking...'
if ! nmcli networking off; then
echo 'nmcli, command disabling networking, is not happy' >&2
exit 1
fi
echo 'Networking is disabled.'
echo
echo 'All is good'
echo '==============================='
exit 0
Here is the corntab line (created using sudo crontab -e)
@reboot /home/noor/bin/go-offline-1.0 >> /home/noor/go-offline.log 2>&1
Contents of log file:
Deleting all existing connections...
Error: NetworkManager is not running.
Error: NetworkManager is not running.
shit happens while deleting connections
I guess that at the point of executing my script in the boot process, NetwrokManager is not yet activated.
Also after a quick exchange with ChatGPT, I tried to make script run as part of the shut down process rather than at startup using systemlc or sth, but it didn't work for some reason. I don't see reason to mention its details.
I had an idea to alias poweroff command so that it executes my script then shut down the computer. I don't know whether it's a good idea but I am looking for a better solution anyway.
I welcome all useful responses related to any part of this, including fixes to this method or completely different approach.
Thank you!
Asked by mark coder
(49 rep)
Jul 21, 2025, 11:14 AM
Last activity: Jul 21, 2025, 12:25 PM
Last activity: Jul 21, 2025, 12:25 PM