Search
Close this search box.

Linux wget and http authentication

Table of Contents

Learn All About Linux wget and HTTP authentication

We covered how to enable HTTP authentication in Nginx web server in a previous article

Nginx HTTP Authentication on your Linux VPS

As a result, we also need to cover how to fetch web objects with wget when the objects require http basic authentication.

wget basic auth picture
wget basic auth picture

HTTP Basic authentication allows to protect of web locations or subdomains with a basic user/password authentication schema.

Wget is the tool to download http/https pages or objects from your Linux VPS CLI and, fortunately, it can fetch these resources even if they are protected with HTTP basic auth. For resources protected with session/cookie systems, it is more complex.

 

Wget files from HTTP authentication websites

$ wget --http-user=[HTTP-USER] --http-passwd=[HTTP-PASSWORD] https://server1.domain.com/vault/file.xml

Since the username and password used by wget to perform the HTTP authentication are used in a CLI, they will remain in your shell’s history. Make sure you clear these lines by logging out and logging back in and editing the history file. For bash, it is .bash_history in your root directory.

You can actually create these settings on our platform in a few minutes utilizing our PCS (Private Cloud Solution) which allows you to have VPSie(s) on a private network – NAT – Port forward – traffic control for inbound and outbound – multiple gateway IPs which you could use for the load-balancing and failover.

Free BSD New user

FAQ

wget is a command-line utility used for downloading files from the internet. It supports downloading files over HTTP, HTTPS, and FTP protocols.

To use wget for HTTP authentication, you need to provide the username and password as part of the URL. For example:

 

CSS
 
wget --http-user=USERNAME --http-password=PASSWORD http://example.com/file.zip

 

Alternatively, you can create a .netrc file in your home directory and add the following lines:

 
machine example.com login USERNAME password PASSWORD

 

Then run wget without any authentication flags:

python
 
wget http://example.com/file.zip

You can use the -i flag to download multiple files listed in a text file, each on a separate line. You will need to provide the HTTP authentication details in the URL for each file. For example:

 

CSS
 
wget --http-user=USERNAME --http-password=PASSWORD -i files.txt

Where files.txt contains a list of URLs, each with their own authentication details:

 

python
 
http://example.com/file1.zip http://example.com/file2.zip http://example.com/file3.zip

You can use the -i flag to download multiple files listed in a text file, each on a separate line. You will need to provide the HTTPS authentication details in the URL for each file. For example:

 

CSS

 
wget --user=USERNAME --password=PASSWORD -i files.txt

Where files.txt contains a list of URLs, each with its own authentication details:

 

Python
 
https://example.com/file1.zip https://example.com/file2.zip https://example.com/file3.zip

Yes, you can create a .wgetrc file in your home directory and add the following lines:

 

makefile
 
user=USERNAME password=PASSWORD

 

This will save your authentication details for all future wget commands. However, it is not recommended for security reasons, especially if you are sharing the computer with other users. It is better to use the .netrc file or provide the authentication details in the command line.

Make a Comment
Share on
Facebook
Twitter
LinkedIn
Print
VPSie Cloud service

Fast and Secure Cloud VPS Service

Try FREE
For a month

The First 1 orders gets free discount today! Try Sign up on VPSie to get a chance to get the discount.