Blog

Thoughts from my daily grind

Connecting to WiFi using Terminal - macOS

Posted by Ziyan Junaideen |Published: 12 October 2021 |Category: Apple
Default Upload |

Connecting to a new Wi-Fi network is not something many of you do often. But for some of us who end up visiting clients and giving lectures, connecting to new Wi-Fi networks is a daily task. Carrying a MacBook you already look cool. If you connect to Wi-Fi through the terminal you will emanate superiority. 🤭

Why use the terminal?

The real question is, "why not use the terminal?". The terminal is undoubtedly the fastest and most efficient way to interact with the computer with minimal strain on the wrist (bye-bye carpal tunnel syndrome 👋).

You can get a lot done by memorizing few commands and their usages. Interestingly you can easily recall them from history.

Procedure

Step 1: Identify the Wi-Fi SSID

Usually, any organization that has Wi-Fi will give you the SSID with the password. But in case you didn't, you can use the airport command to find available Wi-Fi networks and thier SSIDs.

⇒  airport -s
                      SSID BSSID             RSSI CHANNEL HT CC SECURITY (auth/unicast/group)
                 Dialog 4G 00:e0:4c:11:8d:00 -91  10      Y  -- WPA(PSK/TKIP,AES/TKIP) WPA2(PSK/TKIP,AES/TKIP)
                    SUSIRI 9c:74:1a:8e:3f:f0 -90  5       Y  LK WPA(PSK/AES,TKIP/TKIP) WPA2(PSK/AES,TKIP/TKIP)
            ZiyanJunaideen 8c:e1:17:a0:84:4a -44  5       Y  #a WPA(PSK/AES/AES) WPA2(PSK/AES/AES)

Note: If you do not have airport (command not found), that is becuase it is by default hidden deep inside macOS. Follow these instructions to make it accessible anywhere.

Step 2: Identify your device name

If you are in a MacBook, the chances are this would be en0. This will depend on your available ports. So lets find out the device name of our Wi-Fi. That is what the command networksetup -listnetworkserviceorder will do.

jdeen@iMac:~|⇒  networksetup -listnetworkserviceorder
An asterisk (*) denotes that a network service is disabled.
(1) Ethernet
(Hardware Port: Ethernet, Device: en0)

(2) Wi-Fi
(Hardware Port: Wi-Fi, Device: en1)

(3) Bluetooth PAN
(Hardware Port: Bluetooth PAN, Device: en4)

(4) Thunderbolt Bridge
(Hardware Port: Thunderbolt Bridge, Device: bridge0)

(5) Test
(Hardware Port: com.wireguard.macos, Device: )

Here we see that the Wi-Fi device is en1.

Step 3: Connecting to Wi-Fi with password:

Based on the above information my device name is en1 and I need to connect to the Wi-Fi network with the SSID ZiyanJunaideen. Assume that the password for the network is password.

networksetup -setairportnetwork en1 <NETWORK_SSID> <NETWORK_PASSWORD>
networksetup -setairportnetwork en1 ZiyanJunaideen password

That wasn't that hard or intimidating, was it. The terminal is efficient and cool. Always try to do it in presentation mode when everyone is there and enjoy listening to the executives' hoot like owls.

Happy "hacking" beloved Apple geeks!

Tags
About the Author

Ziyan Junaideen -

Ziyan is an expert Ruby on Rails web developer with 8 years of experience specializing in SaaS applications. He spends his free time he writes blogs, drawing on his iPad, shoots photos.

Comments