Connect to WiFi network using Mac Terminal

35,619

Solution 1

As of Snow Leopard (Mac OS X v10.6.x) and possibly earlier, you can do:

networksetup -setairportnetwork $INTERFACE $SSID $PASSWORD

Where...

  • $INTERFACE is the "enX" style identifier for your AirPort card (usually en1, but it's en0 on MacBook Airs and en2 on Mac Pros, and can vary for other reasons as well)
  • $SSID is your network name, such as "Simon's SSID". Enclose it in quotes if it contains spaces.
  • $PASSWORD is your WEP, WPA-PSK, or WPA2-PSK password.

If you look at the man page or help/usage statement for networksetup you'll see that it has other AirPort-related subcommand for getting or setting the power state (AirPort card on/off), and for managing the Preferred Networks list and 802.1X profiles (if your network uses 802.1X, such as a WPA Enterprise or WPA2 Enterprise network would).

Solution 2

Figured it out:

sudo airport -A

Solution 3

Here is a little guide on using airport in the Command Line

Apparently you can use

$ airport 

as a command. I would try

$ airport -help

and see if it brings up some options.

This answer is outdated. Please ignore it

Share:
35,619

Related videos on Youtube

User19
Author by

User19

Updated on September 18, 2022

Comments

  • User19
    User19 over 1 year

    Every time I try to find out how to do this, I find out how to do it on a linux, and it doesn't transfer. How do I connect to a WiFi network using Mac Terminal Bash?

  • Simon Sheehan
    Simon Sheehan about 13 years
    Put it into quotations. Like "Simon's SSID". So the command may be something like: airport -x "Simon's SSID"
  • User19
    User19 about 13 years
    @Simon what would the -x do? @nathang why would it change? How do I find what the correct location on my computer would be?
  • Spiff
    Spiff about 13 years
    How in the world did this answer, which has no hope of working, get upvotes?
  • slhck
    slhck almost 13 years
    The guide is from 2007, just saying.
  • Simon Sheehan
    Simon Sheehan almost 13 years
    -x was just to represent any variable. I had a friend try the command, and he told me that some options came up. Clearly I was mistaken, I apologize.
  • Luxspes
    Luxspes over 10 years
    there is no "-A" option in airport
  • Luigi Ranghetti
    Luigi Ranghetti over 7 years
    Probably should gave have been s … which is the key next to a on a keyboard.