getting my wifi name and password from the terminal#prevsinglenexttop
I often want to get my current WiFi name (SSID) and password.
How to get name/password manually
Sometimes, it's for a microcontroller. Sometimes, to share it. This time, it's for setting up an info-beamer device with WiFi.
Before today, I would usually open my phone and go to "share" under the WiFi settings, and copy the password manually, and also copy the SSID manually.
It's finally time to write a way to do it with bash!
How to get name/password with bash
After some web-searching, these commands do what I want:
alias wifi=iwgetid -r
alias wifipw=sudo cat "/etc/NetworkManager/system-connections/$(wifi).nmconnection" | pcregrep -o1 "^psk=(.*)"
How to use
…and I can use them like:
$ wifi
the wood raft (2.4G)
$ wifipw
[sudo] password for alifeee:
**************
Neat!
Using Atuin aliases
Finally, above I suggested I was using Bash aliases, but I actually created them using Atuin, specifically Atuin dotfile aliases, like:
atuin dotfiles alias set wifi 'iwgetid -r'
atuin dotfiles alias set wifipw 'sudo cat "/etc/NetworkManager/system-connections/$(wifi).nmconnection" | pcregrep -o1 "^psk=(.*)"'
Now, they will automatically be enabled on all my computers that use Atuin. This is actually not… amazingly helpful as my other computers all use ethernet, not WiFi, but… it's mainly about having the aliases all in the same place (and "backed up", if you will).