# connect to wifi via commandline on arch

I just spent hours connecting to the wireless network on archlinux today. Finally I resorted to various tools in commandline. Here’s how I do it. Make sure you run the following commands as root to avoid some permission errors.

# Find out SSID of the target wifi

Replace your_interface with your own one, usually it’s wlp3s0 or wlan0. You can run ifconfig to find out the name of your interface

You will get something like

The SSID is something after SSID. It’s TP-LINK_7474 in my case.

# Association

After finding out your SSID, you would need to connect to it. There are two cases here, one is when there’s no encryption and one is when WPA/WPA2 is enabled. Find the case that suits you most.

## No Encryption

This is pretty easy, you only need one line here.

your_essid is the name of the network you found out before, such as TP-LINK_7474

Then you will need to Get an IP address

## WPA/WPA2

You have a lot of work to be done here. First create a new file /etc/wpa_supplicant/wpa_supplicant.conf. Type in the following contents and save it.

Generate passphrase and save it to the above file. Replace your_SSID and your_key with your own ones.

Check if wpa_supplicant is running.

If it’s running, just as follows

Kill the process, and remove /var/run/wpa_supplicant/ if it exists

If it’s not running or you’ve killed the running one, run the following command to start wpa_supplicant.

After connect to the network, you need to get an IP using dhcpcd