Easy Steps To Check Connected WiFi Password on Ubuntu Linux

Posted on

Easy Steps To Check Connected WiFi Password on Ubuntu Linux

Easy Steps To Check Connected WiFi Password on Ubuntu Linux

This tutorial aims to guide you on how to View the Saved WiFi Passwords and Check Connected WiFi Password on Ubuntu Linux from the Command Line Terminal.

If you’re using wireless connections and frequently connecting to various WiFi access points, your Ubuntu system diligently saves the passwords for these connections. However, there might come a time when you forget a particular password. Don’t worry; you can easily retrieve it by following the steps outlined below to Check Connected WiFi Password on Ubuntu Linux.

Before proceeding, ensure you have access to your Ubuntu server as a non-root user with sudo privileges. If you need assistance with this, refer to Ubuntu initial server setup guides. These guides are readily available for various Ubuntu versions, including Ubuntu 20.04 and Ubuntu 22.04.

Step 1 – Check Saved WiFi Passwords on Ubuntu Terminal

First, you can list all the saved WiFi connections on your Ubuntu system directly from the Linux terminal. To achieve this, navigate to the /etc/NetworkManager/system-connections/ directory using the following command:

sudo cd /etc/NetworkManager/system-connections/

Once inside the directory, list all the files and directories using the ls -a command:

ls -a

This directory contains the profiles for all your saved WiFi connections. Each WiFi network you’ve previously connected to has its own profile file containing the connection details.

To view the contents of a specific WiFi profile, use the cat command followed by the name of the profile file. For example:

sudo cat [<mark>name of profile</mark>]

Within the profile file, you’ll find the saved password associated with that WiFi network. Look for the psk option under the [wifi-security] section. This is where the password is stored.

Step 2 – Find the Current Connected WiFi Password on Ubuntu Terminal

To retrieve the password for the WiFi network you are currently connected to, execute the following command in your terminal:

sudo nmcli device wifi show-password

This command will display the current connected WiFi password, along with a QR code that you can use to share the connection with others.

That concludes the process of viewing and retrieving WiFi passwords on Ubuntu Linux using the command line.

Conclusion

Using the Linux Command Line is a powerful way to manage and Check Connected WiFi Password on Ubuntu Linux. We have demonstrated how to View the Saved WiFi Passwords and Check the Connected WiFi Password on Ubuntu Linux from the Command Line Terminal. With just a few simple Linux commands, you can easily access and retrieve your saved WiFi passwords.

Here are some related articles that you might find interesting:

Web Browsing on AlmaLinux Terminal

Set Static IP Address on Ubuntu 22.04 From CLI

Alternative Methods to Retrieve WiFi Passwords on Ubuntu Linux

While the command-line approach outlined above is effective, there are alternative methods to retrieve WiFi passwords on Ubuntu Linux. These methods offer different levels of convenience and may be more suitable depending on your specific needs and technical expertise. Here are two such alternatives:

1. Using the Graphical User Interface (GUI)

For users who prefer a graphical interface, Ubuntu provides a straightforward way to view and manage WiFi passwords through the Network Manager settings. This method is particularly useful for those less comfortable with command-line operations.

Steps:

  1. Open Network Settings: Click on the network icon in the system tray (usually located in the top-right corner of the screen). Select "Settings" or "Network Settings" from the dropdown menu.

  2. Select WiFi: In the Network Settings window, choose "WiFi" from the left-hand sidebar.

  3. Select the Network: Find the name of the WiFi network whose password you want to view. If you are currently connected, it will be listed at the top. If not, you may need to select it from the list of available networks.

  4. Show Password: Click the gear icon (settings) next to the network name. In the network settings window that appears, go to the "Security" tab. There should be a "Password" field with a checkbox labeled "Show password." Check this box.

  5. Authenticate: You might be prompted to enter your user password to authenticate and view the WiFi password. Enter your password and click "Authenticate."

The password for the selected WiFi network will now be displayed in the "Password" field. You can copy this password or simply note it down.

Advantages:

  • User-friendly and intuitive, especially for users unfamiliar with the command line.
  • No need to remember specific commands or syntax.
  • Provides a visual representation of the network settings.

Disadvantages:

  • Requires a graphical environment, which may not be available on headless servers.
  • Can be slower than the command-line method for experienced users.
  • May require authentication with your user password.

2. Decrypting the Passwords Using libsecret

Another alternative is to use libsecret, a library that provides a secure way to store and retrieve passwords. This method is more technical but can be useful in scripting and automation scenarios. This method is more complex, but it avoids directly reading the configuration files.

Explanation:

Ubuntu uses libsecret to store network passwords. We can leverage its tools to decrypt and reveal these passwords. This approach has the advantage of using the proper API, respecting the encryption and access control mechanisms in place.

Steps and Code Example:

  1. Install Dependencies: Ensure that you have the necessary packages installed. If not, install them using the following command:

    sudo apt-get install libsecret-1-0 libsecret-tools
  2. Identify Connection UUID: We need to find the UUID (Universally Unique Identifier) of the connection whose password you want to retrieve. List the connections managed by NetworkManager:

    nmcli connection show

    This command will output a list of connection names and their corresponding UUIDs. Note down the UUID of the WiFi connection you are interested in.

  3. Decrypt and Retrieve Password: Use the secret-tool command to retrieve the password associated with the connection UUID. Replace <UUID> with the actual UUID you noted in the previous step.

    secret-tool search --unlock network-manager-ssid <SSID>  -- attributes SSID=<SSID> | awk 'NF {printf $NF} '

    Replace <SSID> with the SSID (network name).

Complete Example Script:

To make this process easier, you can create a simple bash script:

#!/bin/bash

# Get the SSID of the currently connected Wi-Fi network
SSID=$(iwget config | grep SSID | awk '{print $2}' | tr -d '"')

# Check if the SSID is empty
if [ -z "$SSID" ]; then
  echo "Not connected to any Wi-Fi network."
  exit 1
fi

# Use secret-tool to retrieve the password
PASSWORD=$(secret-tool search --unlock network-manager-ssid "$SSID" -- attributes SSID="$SSID" | awk 'NF {printf $NF} ')

# Check if the password was found
if [ -z "$PASSWORD" ]; then
  echo "Password not found for SSID: $SSID"
  exit 1
fi

# Display the SSID and password
echo "SSID: $SSID"
echo "Password: $PASSWORD"

exit 0

Save this script to a file, for example, get_wifi_password.sh, make it executable, and then run it:

chmod +x get_wifi_password.sh
./get_wifi_password.sh

Advantages:

  • More secure, as it utilizes the system’s password storage mechanisms.
  • Suitable for scripting and automation.
  • Avoids directly accessing and parsing configuration files.

Disadvantages:

  • More complex and requires some technical knowledge.
  • Involves installing additional packages.
  • May require adjusting permissions and configurations.

By understanding these alternative methods, you can choose the approach that best suits your technical skills and the specific situation when you need to Check Connected WiFi Password on Ubuntu Linux.

Leave a Reply

Your email address will not be published. Required fields are marked *