How to Use aria2c with Basic Authentication on Ubuntu
This article provides a concise guide on utilizing the aria2c download utility within the Ubuntu operating system to access files protected by basic authentication. It covers the necessary command-line flags for inserting credentials directly and offers a secure alternative using a configuration file to prevent password exposure in shell history.
Installing aria2 on Ubuntu
Before downloading files, ensure aria2 is installed on your system. Open your terminal and run the following command to install the package from the default repositories:
sudo apt update
sudo apt install aria2Using Command-Line Flags
The most direct method to authenticate is by passing your username
and password directly within the command using the
--http-user and --http-passwd options. The
syntax follows this structure:
aria2c --http-user=YOUR_USERNAME --http-passwd=YOUR_PASSWORD https://example.com/file.zipReplace YOUR_USERNAME and YOUR_PASSWORD
with your actual credentials and update the URL to point to the target
file. While effective, be aware that passwords entered this way may be
visible in your shell history.
Using a .netrc File for Security
To avoid exposing passwords in command history, you can store
credentials in a .netrc file in your home directory. Create
or edit the file using a text editor:
nano ~/.netrcAdd the following line, replacing the details with your server information:
machine example.com login YOUR_USERNAME password YOUR_PASSWORD
Save the file and secure its permissions so only you can read it:
chmod 600 ~/.netrcOnce configured, you can run aria2c without specifying credentials explicitly:
aria2c https://example.com/file.zipVerifying the Download
After executing the command, aria2c will attempt to connect to the server. If the authentication credentials are correct, the download will begin immediately. You can verify the success of the operation by checking the exit code or listing the downloaded file in your current directory.
ls -lh file.zipIf the download fails due to authentication errors, double-check your username, password, and the URL for accuracy.