Join a Wi-Fi Network from the Terminal

Use networksetup -setairportnetwork to connect your Mac to a Wi-Fi network by name and password without touching the Wi-Fi menu.

macOSnetworknetworksetupWi-FiLow risk
Run `networksetup -setairportnetwork en0 "SSID" "password"` to connect to the network immediately.

01Command

Command
$ networksetup -setairportnetwork en0 "HomeWiFi" "wifipassword"

02What it does

The Wi-Fi menu is a GUI wrapper around the same association request this command makes, so it works even when the menu bar icon is stuck or you are connected over Screen Sharing. Replace en0 with your actual Wi-Fi interface if different (check with `networksetup -listallhardwareports`). Quote the SSID if it contains spaces, and note the password is passed on the command line where it can appear in your shell history.

03Risk

RiskLow risk
RequirementsYou need the network name (SSID) and password; en0 is the built-in Wi-Fi interface on most Macs (check with `networksetup -listallhardwareports`).
!Warning: The Wi-Fi password appears in plain text in your shell history — clear the history line if the Mac is shared.

04Undo

✓No undo needed — this command does not change persistent state.

05Sources

Last verified: 2026-09-18 · Category: Network

06Related solutions