Nmap prints requires root privileges (or Failed to open device, or Only root can do that) when you ask it for a scan type that needs to build packets itself. It is a permissions message, not a network problem, and there are three legitimate answers depending on why you cannot be root.
Why a port scan needs privileges at all
There are two ways to test whether a TCP port is open. The connect scan calls the operating system's connect(), exactly as a browser does — any user may do that. The SYN scan builds the TCP packet itself, sends it, and reads the reply from a raw socket, never completing the handshake. Building packets is restricted to root or to a process holding CAP_NET_RAW, because a raw socket can forge any packet, including someone else's source address.
Nmap's default scan type for a privileged user is the SYN scan (-sS), which is why the message appears so often. For an unprivileged user the default falls back to the connect scan and simply works.
| What you asked for | Needs raw sockets? | Works as a normal user? |
|---|---|---|
nmap host (default) | No, falls back to connect scan | Yes |
-sT connect scan | No | Yes |
-sS SYN scan | Yes | No |
-sU UDP scan | Yes | No |
-O OS detection | Yes | No |
-PR ARP scan (local network) | Yes | No |
-sV version detection | No, once a scan type is chosen | Yes, with -sT |
-sn ping sweep | Depends on probe | Yes, with TCP probes |
-D decoys, -S source spoofing | Yes | No |
Option 1: run it as root
The intended answer, and the right one for a one-off scan:
sudo nmap -sS -sV -p- 192.0.2.10
For automation, avoid sudo in a script that also runs untrusted input; a narrow sudoers entry limited to the exact nmap arguments is safer than a blanket rule. Either way, scan only hosts you own or have written permission to test.
Option 2: connect scan, no privileges needed
If you cannot elevate, ask for the scan type that uses the operating system's own connect call:
nmap -sT -sV -p 22,80,443 192.0.2.10
What this costs you:
- It is slower per port, because each probe finishes a full TCP handshake.
- It is louder. A completed connection is a real connection: the service logs it, and an application firewall sees a session rather than a stray packet.
- No OS detection and no UDP. Both fundamentally need raw sockets.
For checking your own server's open ports, none of that matters. For anything resembling a real assessment, the difference matters a lot.
Option 3: give the binary a capability
Linux can grant the specific rights nmap needs to the executable instead of to the user. Install libcap2-bin and run:
sudo setcap cap_net_raw,cap_net_admin,cap_net_bind_service+eip $(which nmap)
getcap $(which nmap)
# /usr/bin/nmap = cap_net_raw,cap_net_admin,cap_net_bind_service+eip
nmap --privileged -sS 192.0.2.10
--privileged is required: with it, nmap assumes it has the capabilities it was granted instead of checking whether you are root. Without it nmap still refuses.
Understand the trade-off before you do this. The capability belongs to the binary, so every user on that machine can now send raw packets through nmap. On a shared or CI host that is a privilege escalation you handed out for convenience. Undo it with:
sudo setcap -r $(which nmap)
A container or a dedicated scanner VM is the cleaner place for this than a workstation.
Inside a container
Containers drop capabilities by default, so nmap in Docker hits the same wall even as root:
docker run --rm --cap-add=NET_RAW --cap-add=NET_ADMIN instrumentisto/nmap -sS 192.0.2.10
--privileged also works and is a much wider grant than most people realise — prefer the two named capabilities.
macOS and Windows
- macOS:
sudo nmap -sS .... The connect scan works without sudo, with the same limits as on Linux. - Windows: install Npcap during setup (it ships with the nmap installer) and run the terminal as Administrator for SYN and UDP scans. Without Npcap the installer's "WinPcap compatibility" prompt is where most people go wrong: skip it and only connect scans work.
When it is not a privilege problem
Two messages look similar and are not:
Failed to open device eth0— nmap asked for a specific interface it cannot open. Check the name withip link; containers often have a different interface than the host.QUITTING!afterUnable to find nmap-services— a broken or partial install, not permissions. Reinstall the package rather than reaching for sudo.
Frequently asked
Can I do a UDP scan without root?
No. Sending a bare UDP probe needs a raw socket. Use the SYN/connect TCP scan instead and check UDP from a privileged host.
Does --unprivileged help?
It tells nmap to behave as if it has no privileges. It is useful to reproduce what a normal user sees; it cannot grant anything.
Why does -O need root even with -sT?
OS detection analyses how a machine builds its own packets, which means crafting probes and reading raw replies. There is no userspace fallback.
Related
The nmap cheat sheet has the command shapes for each scan type, the nmap tool guide covers the workflow around it, and nmap vs masscan and nmap vs rustscan explain when raw-socket speed is worth the effort.
See also: Nmap "Host Seems Down" / "No Route to Host" — capture-device and route errors are often the same permissions problem.