Commands.page Logo

How to Use HTTP Authentication with aria2c on Ubuntu

This guide explains how to configure HTTP basic authentication when using the aria2c command-line utility on Ubuntu. You will learn the specific flags required to pass usernames and passwords securely, how to handle special characters, and how to save credentials in a configuration file for repeated use. By following these steps, you can automate restricted downloads without manual intervention.

Using Command Line Flags

The most direct method to authenticate is by passing arguments directly in your terminal command. aria2c provides specific options for HTTP basic authentication. Use the --http-user flag for your username and the --http-passwd flag for your password.

The syntax follows this structure:

aria2c --http-user=your_username --http-passwd=your_password http://example.com/file.zip

Replace your_username and your_password with your actual credentials. Ensure there are no spaces between the flag, the equals sign, and the value. If your password contains special characters, wrap it in single quotes to prevent shell interpretation errors.

Using a Configuration File

For frequent downloads from the same source, storing credentials in a configuration file is more efficient. This prevents you from typing sensitive information repeatedly and keeps your command history clean.

  1. Create or open the aria2 configuration file located at ~/.aria2/aria2.conf.
  2. Add the following lines to the file:
http-user=your_username
http-passwd=your_password
  1. Save the file and restrict its permissions so only you can read it:
chmod 600 ~/.aria2/aria2.conf

When you run aria2c subsequently, it will automatically read these settings. You can still override them in the command line if needed for a specific download.

Security Considerations

Be cautious when using passwords in command lines. Commands are often saved in your shell history, which could expose your credentials to anyone with access to your user account. Using the configuration file with restricted permissions is the recommended security practice. Additionally, ensure you are downloading over HTTPS whenever possible to encrypt the transmission of your authentication data.

Troubleshooting Authentication Errors

If you receive a 401 Unauthorized error, double-check your username and password for typos. Some servers require specific authentication realms or may not support basic authentication over insecure HTTP connections. Verify that the URL is correct and that the server supports the authentication method you are attempting to use. If problems persist, enable verbose logging with the -V flag to inspect the HTTP headers exchanged during the connection attempt.