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.
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
!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
- networksetup — configure network settings (macOS man page)Evidence: Documents `networksetup -setairportnetwork <hardwareport> <network> [password]` for joining a wireless network from the command line.
- Connect to the internet on your MacEvidence: Describes joining a Wi-Fi network by selecting its name and entering the password — the same association the setairportnetwork command performs.
Last verified: 2026-09-18 · Category: Network