Connect to Wifi in Linux with nmcli
nmcli
is a command line tool for interacting with NetworkManager which handles wifi. It is useful as it is installed in many distros by default, and therefore provides a standardized way of connecting to wifi and managing connections.
Connect to Wifi
nmcli d wifi list --rescan yes
note: d
is short for device
and --rescan yes
makes sure that nmcli scans for wifis before listing them.
Output:
IN-USE BSSID SSID MODE CHAN RATE SIGNAL BARS SECURITY
NN:NN:NN:NN:NN:NN Internet-one Infra 3 270 Mbit/s 65 ▂▄▆_ WPA2
NN:NN:NN:NN:NN:NN Internet-two Infra 36 270 Mbit/s 49 ▂▄__ WPA2
NN:NN:NN:NN:NN:NN third-internet-ssid Infra 10 270 Mbit/s 47 ▂▄__ WPA2
NN:NN:NN:NN:NN:NN your-wifi Infra 5 403 Mbit/s 35 ▂▄▆_ WPA1 WPA2
NN:NN:NN:NN:NN:NN awesome Infra 44 270 Mbit/s 39 ▂▄__ WPA2
NN:NN:NN:NN:NN:NN totaly-secure-wifi Infra 9 405 Mbit/s 35 ▂▄__ WPA1 WPA2
Select the SSID of your internet and connect to it like this:
nmcli d wifi connect "your-wifi" --ask
note: --ask
prompts you for a password if needed.
Connections
When you have connected to a wifi, the wifi will be saved as a connection, and you will not have to provide your password again. You can run the following command to see all the stored connections.
nmcli c show
note: c
is short for connection
.
The connections are stored in /etc/NetworkManager/system-connections
. This folder can only be accessed by root
. Inside each connection file metadata about the wifi is stored, this includes its password in plain text!
This makes is possible to transfer all your connections to another computer by simply copying the connections over. The new computer will now automatically connect to the transferred wifis.
Getting more Information
This is of course not everything nmcli
can do. If you want to find out more about nmcli
you can view the manual online or simply read the manual in the terminal like this:
man nmcli
And if you need a list of options in a command just run this:
nmcli [command] -h