Skip to main content

Why Root Permissions Are Required

AutoPentestX uses Nmap for network scanning, which requires root (sudo) privileges for several scan techniques:

SYN Scans (-sS)

Raw packet manipulation requires root access to create custom TCP packets

OS Detection (-O)

Low-level network probes need raw socket access

Service Detection (-sV)

Some service fingerprinting techniques require privileged ports

Raw Sockets

Direct network interface access is restricted to root user
Without sudo, Nmap falls back to TCP connect scans (-sT), which are slower, noisier, and easier to detect. You may also get incomplete results.

Common Permission Errors

Error Message:
[!] OS Detection failed: Permission denied
nmap.nmap.PortScannerError: 'nmap returned: 
You requested a scan type which requires root privileges.'
Cause: Running AutoPentestX without sudo privileges.Solution:
Run the entire script with sudo:
sudo python3 main.py -t 192.168.1.100
Or using the wrapper script:
sudo ./autopentestx.sh 192.168.1.100
Error Messages:
PermissionError: [Errno 13] Permission denied: 'reports/'
sqlite3.OperationalError: unable to open database file
OSError: [Errno 13] Permission denied: 'logs/autopentestx.log'
Cause: Insufficient write permissions for output directories.Solution:
1

Check current permissions

ls -la reports/ logs/ database/
2

Fix directory permissions

# Make directories writable
chmod 755 reports/ logs/ database/ exploits/

# If needed, change ownership
sudo chown -R $USER:$USER reports/ logs/ database/ exploits/
3

Recreate directories if missing

mkdir -p reports logs database exploits
chmod 755 reports/ logs/ database/ exploits/
4

Verify fix

# Test write access
touch reports/test.txt && rm reports/test.txt && echo "✓ Write access OK"
The install.sh script automatically creates these directories with proper permissions. Re-run it if directories are missing.
Error Message:
bash: ./install.sh: Permission denied
bash: ./autopentestx.sh: Permission denied
bash: ./main.py: Permission denied
Cause: Execute bit not set on shell scripts or Python files.Solution:
# Make scripts executable
chmod +x install.sh
chmod +x autopentestx.sh
chmod +x main.py
chmod -R 755 modules/

# Verify
ls -lh *.sh *.py
Alternative: Run explicitly with interpreter:
bash install.sh
python3 main.py -t 192.168.1.100
Error Message:
PermissionError: [Errno 13] Permission denied: '/home/user/AutoPentestX/venv/bin/pip'
Could not install packages due to an EnvironmentError
Cause: Virtual environment created with wrong ownership (often happens when using sudo).Solution:
1

Remove corrupted venv

rm -rf venv
2

Recreate WITHOUT sudo

# IMPORTANT: Don't use sudo here!
python3 -m venv venv
3

Activate and install packages

source venv/bin/activate
pip install -r requirements.txt
4

Fix ownership if needed

# Only if venv was created with sudo
sudo chown -R $USER:$USER venv/
NEVER create virtual environments with sudo. This causes permission conflicts and security issues.

Understanding Sudo and AutoPentestX

When Sudo is Required

These operations REQUIRE sudo:✅ Full system scans with SYN scanning
sudo python3 main.py -t 192.168.1.100
✅ OS detection and fingerprinting
sudo python3 main.py -t example.com
✅ Raw packet manipulation
sudo nmap -sS -O 192.168.1.100
✅ Installing system packages
sudo apt-get install nmap nikto sqlmap

Security Best Practices

Principle of Least Privilege

Only use sudo when necessary. Don’t run entire sessions as root.
# Good
sudo python3 main.py -t 192.168.1.100

# Bad
sudo su
python3 main.py -t 192.168.1.100

Verify Commands

Always review what you’re running with sudo
# Check script content first
cat install.sh

# Then run with sudo
./install.sh

Limit Sudo Scope

Use sudoers file to grant specific permissions
# Only allow Nmap with sudo
username ALL=(ALL) NOPASSWD: /usr/bin/nmap

Audit Sudo Usage

Review sudo logs regularly
# Check sudo history
cat /var/log/auth.log | grep sudo
journalctl -u sudo

Docker Alternative (No Sudo Required)

If you want to avoid sudo permission issues entirely, consider running AutoPentestX in Docker:
Dockerfile
FROM kalilinux/kali-rolling

RUN apt-get update && apt-get install -y \
    python3 python3-pip nmap nikto sqlmap metasploit-framework

WORKDIR /autopentestx
COPY . .

RUN pip3 install -r requirements.txt

ENTRYPOINT ["python3", "main.py"]
Build and Run
# Build container with root access
docker build -t autopentestx .

# Run without sudo on host (container has root inside)
docker run --rm autopentestx -t 192.168.1.100
Docker containers run with root privileges by default, so Nmap gets the permissions it needs without requiring sudo on your host system.

Checking Current Permissions

Use these commands to diagnose permission issues:
System Information
# Check if you're root
whoami
id

# Check sudo access
sudo -v

# View sudo permissions
sudo -l
File Permissions
# Check directory permissions
ls -la reports/ logs/ database/

# Check file ownership
stat reports/ logs/ database/

# View ACLs (if applicable)
getfacl reports/
Test Access
# Test Nmap with sudo
sudo nmap -sS localhost

# Test write permissions
touch reports/test.txt && rm reports/test.txt

# Test database access
sqlite3 database/autopentestx.db "SELECT 1;"

Troubleshooting Checklist

Before asking for help with permission issues, verify:
1

Running with sudo

sudo python3 main.py -t 192.168.1.100
✅ Using sudo for network scanning
2

Directories exist

mkdir -p reports logs database exploits
✅ All required directories created
3

Correct ownership

ls -la | grep -E "reports|logs|database|exploits"
✅ Directories owned by your user
4

Scripts executable

chmod +x install.sh autopentestx.sh main.py
✅ Execute permissions set
5

Venv not root-owned

ls -la venv/
✅ Virtual environment owned by your user, not root

Related Documentation

Build docs developers (and LLMs) love