DeveloperBreeze

How to Connect to WiFi from a Root Shell in Ubuntu

Introduction

Sometimes, you may find yourself needing to connect to a WiFi network from a root shell, especially when troubleshooting or working in a minimal environment without a graphical interface. This guide provides step-by-step instructions on how to connect to WiFi from a root shell using the nmcli and wpa_supplicant commands in Ubuntu.

Step 1: Identify Available WiFi Networks

Before connecting to a WiFi network, you need to identify the available networks:

  1. Use nmcli to list available WiFi networks:
   nmcli dev wifi list

This command lists all available WiFi networks, showing details such as SSID (network name), signal strength, and security type.

  1. Note the SSID of the network you want to connect to.

Step 2: Connect to the WiFi Network Using nmcli

nmcli is a command-line tool for managing NetworkManager, which controls network connections in Ubuntu.

  1. Connect to the WiFi network:
   nmcli dev wifi connect "SSID" password "your_password"

Replace "SSID" with the name of your WiFi network and "your_password" with the network’s password.

  1. Verify the connection:

After running the command, you should see a message indicating that the device has successfully connected to the network. To verify:

   nmcli dev status

This command shows the status of your network interfaces, confirming if the WiFi connection is active.

Step 3: Manually Connecting Using wpa_supplicant

If nmcli is not available, or you prefer a more manual approach, you can use wpa_supplicant to connect to WiFi.

  1. Create a configuration file for wpa_supplicant:
   sudo nano /etc/wpa_supplicant/wpa_supplicant.conf

Add the following configuration, replacing your_ssid and your_password with your network’s SSID and password:

   network={
       ssid="your_ssid"
       psk="your_password"
   }
  1. Start wpa_supplicant:

Use the following command to connect to the WiFi network:

   sudo wpa_supplicant -B -i wlan0 -c /etc/wpa_supplicant/wpa_supplicant.conf

Replace wlan0 with the name of your wireless interface, which can be found using the ip link command.

  1. Obtain an IP address:

Once connected, obtain an IP address using dhclient:

   sudo dhclient wlan0

This command configures the network interface with an IP address, allowing you to access the internet.

Step 4: Troubleshooting Connection Issues

If you encounter issues connecting to WiFi, here are some troubleshooting steps:

  1. Check the interface status:
   ip link show wlan0

Ensure that your wireless interface is up and running.

  1. Check the logs:

If the connection fails, check the logs for wpa_supplicant:

   sudo journalctl -u wpa_supplicant

This command provides detailed logs that can help diagnose the issue.

  1. Restart the network interface:

If the connection is unstable, try restarting the network interface:

   sudo ip link set wlan0 down
   sudo ip link set wlan0 up

Conclusion

Connecting to WiFi from a root shell is a useful skill, especially when working in a non-GUI environment or troubleshooting network issues. By following this guide, you can easily connect to a WiFi network using either nmcli for simplicity or wpa_supplicant for a more manual approach. These methods ensure that you can maintain network connectivity even when operating at the root level.

Related Posts

More content you might like

Tutorial

ما هو حقن التبعيات (Dependency Injection)؟

يُعد حقن التبعيات أحد أهم المبادئ الشائعة في هندسة البرمجيات، ويهدف إلى تحسين قابلية الصيانة، والاختبار، وإعادة الاستخدام داخل الأنظمة البرمجية. يقوم هذا الأسلوب على فكرة بسيطة: بدلاً من أن تقوم الكائنات (Objects) بإنشاء التبعيات التي تحتاجها بنفسها، يتم حقن هذه التبعيات إليها من الخارج.

بهذه الطريقة، يصبح كل كائن أقل اعتماداً على التفاصيل الداخلية، وأكثر مرونة وقابلاً للاختبار.

Dec 01, 2025
Read More
Article

أفضل طرق إزالة الصدأ من العدّة والمسامير – دليل شامل منزلي واحترافي

تُعد هذه الطرق مناسبة للعِدّة اليدوية أو القطع الصغيرة التي أصابها صدأ خفيف أو متوسط.

  • انقع الأداة في خل أبيض لمدة 12–24 ساعة.
  • افرك السطح بسلك معدني أو فرشة سلك.
  • اغسلها جيدًا بالماء ثم جفّفها فورًا لمنع عودة الصدأ.

Dec 01, 2025
Read More
Tutorial

How to Stop SSH From Timing Out

If your SSH session closes after a minute of inactivity, it’s usually caused by idle timeouts. You can fix this with keep-alive settings on both the server and client.

Edit the SSH daemon config:

Aug 21, 2025
Read More
Tutorial

How to Translate URLs in React (2025 Guide)

import React from 'react';
import { useTranslation } from 'react-i18next';
import { BrowserRouter, Routes, Route, useNavigate } from 'react-router-dom';
import { routes } from './routes';
import './i18n';

const LanguageSwitcher = () => {
  const { i18n } = useTranslation();
  const navigate = useNavigate();

  const switchLang = (lang) => {
    const currentPath = window.location.pathname;
    const currentPage = currentPath.split('/')[1];

    i18n.changeLanguage(lang).then(() => {
      // Re-map path using new language
      const t = i18n.getFixedT(lang);
      const mappedRoutes = {
        en: { accueil: 'home', 'a-propos': 'about-us' },
        fr: { home: 'accueil', 'about-us': 'a-propos' },
      };

      const newPath = `/${mappedRoutes[lang][currentPage] || ''}`;
      navigate(newPath);
    });
  };

  return (
    <div className="lang-switch">
      <button onClick={() => switchLang('en')}>EN</button>
      <button onClick={() => switchLang('fr')}>FR</button>
    </div>
  );
};

const App = () => {
  const { t } = useTranslation();

  return (
    <BrowserRouter>
      <LanguageSwitcher />
      <Routes>
        {routes(t).map((route, idx) => (
          <Route key={idx} path={route.path} element={route.element} />
        ))}
      </Routes>
    </BrowserRouter>
  );
};

export default App;

Create pages/Home.js:

May 04, 2025
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!