Commands.page Logo

How to Use aria2c with Digest Authentication on Ubuntu

This guide explains how to configure the aria2c command-line utility to handle HTTP Digest authentication on Ubuntu systems. You will learn the specific flags required to pass credentials securely and initiate downloads from protected servers without encountering access errors.

Prerequisites

Ensure you have aria2 installed on your Ubuntu machine. If it is not already installed, open your terminal and run the following command:

sudo apt update
sudo apt install aria2

Command Syntax for Digest Authentication

To download a file from a server requiring Digest authentication, you must provide your username and password using specific command-line options. The basic structure requires the --http-user and --http-passwd flags followed by the target URL.

aria2c --http-user=YOUR_USERNAME --http-passwd=YOUR_PASSWORD "URL_TO_FILE"

Practical Example

Suppose you need to download a file located at https://example.com/protected/file.zip using the username admin and the password secret123. The command would look like this:

aria2c --http-user=admin --http-passwd=secret123 "https://example.com/protected/file.zip"

In most cases, aria2c automatically detects the authentication method required by the server, whether it is Basic or Digest. If the server requires a specific challenge handshake that fails initially, you can force the authentication challenge mode by adding the --http-auth-challenge=true flag.

aria2c --http-user=admin --http-passwd=secret123 --http-auth-challenge=true "https://example.com/protected/file.zip"

Security Best Practices

Typing passwords directly into the terminal exposes them in your shell history. For better security, consider using a .netrc file to store your credentials locally with restricted permissions.

  1. Create or edit the file ~/.netrc.
  2. Add the following line: machine example.com login admin password secret123.
  3. Secure the file permissions: chmod 600 ~/.netrc.

Once configured, you can run aria2c without explicitly typing the username and password flags, as the tool will read them from the file automatically.