[HowTo] Connect to internet from command-line as a beginner

Difficulty: ☆☆☆☆☆

Introduction

Connecting to WiFi from the terminal is very useful if you want to use a window manager where you don’t get built-in WiFi connection daemons and utilities in desktop environments. So in order to do that, you’ll need some basic tools. Either use network Utilities which have less features or use a full packed Network Manager. For now, we’ll use a network manager. Though unlike utilities, for no reason should you use multiple of them on your system, as they would conflict with each others. Different distros use different one of these like Ubuntu uses netctl and Fedora, openSUSE and REHL uses NetworkManager. This is also what Manjaro uses as default so we’ll use this for this tutorial, I’ll make more on the other ones later.

1. Using nmtui

Open up a terminal and type nmtui or nmtui-connect and the rest is easy to understand apparently.


You can choose “Activate Connection” from here or directly type nmtui-connect. After that, choose the connection you want to connect and insert your password when prompted.
image
Now, nmtui is really easy to set up, but you cant take the time to configure it every time, and running daemon for wifi is quite confusing and hard to do as a first timer( I’ll cover that on another topic someday). Which brings us to the second method

2. Using nmcli

Open up a terminal and type:

nmcli device wifi connect SSID password YOUR_PASSWORD

Here, SSID means your WiFI friendly name, not the IP address or MAC address or anything. If that consists spaces, use " ".

:warning: Pro tips:

You can use this alias to connect a specific WiFi network without typing all the data:

alias connect_to_my_wifi='nmcli device wifi connect SSID password YOUR_PASSWORD

by E.G. putting this command at the end of your .bashrc or .zshrc file to connect to your WiFi every boot.

Common problem fixes! :
You might see something like this often,

Error: Connection activation failed: (7) Secrets were required, but not provided.

This happens when you login to multiple sessions or users from the same device. To fix it, run this command before connecting to the internet, it makes the system forget about this connection so you can connect afresh again.

nmcli con del YOUR_SSID

Also, you might sometimes have problems with the “device” parameter. To fix that, replace “device” with the Network Interface your system is using. They can be seen with iw dev. You can narrow down the creepy output and print only the interface by

iw dev | awk '$1=="Interface"{print $2}'

Also, you might sometimes have problems with the “device” parameter. To fix that, replace “device” with the Network Interface your system is using. They can be seen with iw dev. You can narrow down the creepy output and print only the interface by

iw dev | awk '$1=="Interface"{print $2}'

So if the output is wlo1, the command would be

nmcli wlo1 wifi connect SSID password YOUR_PASSWORD

Note: Feedback on improving the tutorial is welcomed! :+1:

8 Likes

Great guide :+1:

Finding the device name is not always obvious, i suggest a simple command to find the name of the network device, something like this: $ iw dev | awk '$1=="Interface"{print $2}'

2 Likes

What should I do if the wifi needs user-name and password?

Here, SSID means your WiFI friendly name, not the IP address or MAC address or anything. If that consists spaces, use " ".

It should be "\ "?

type mistake :sweat_smile:

Nice Your help - but in my case there is the response: wlp3s0b1 is not understoodden!

And I tried it also with wdev or ifindex what are the other outputs of the iw command…
Interface wlp32ob1
ifindex 2
wdev 0x1
addr 25 07 …
type managed
txpower 30 db

could there be any other option?