How to Provide a Username and Password to wget?

In Linux, the wget is a utility for downloading files from servers. It has various functionalities, such as resuming the interrupted downloading, downloading files in the background, etc. The wget is a non-interactive network retriever for downloading files from the servers.

This article will cover how I provide the Username and Password to the wget command in Linux. The post’s content is:

How to Provide the Username and Password to the wget Command?

A username and password are provided to the wget command for downloading the file from the protected websites. There are two possibilities while dealing with username and password in the wget command. Let’s explore them one by one through the syntaxes:

Syntax (To Enter Password in the Command):

$ wget --user=<username> --password=<user-password> <URL>

In the above syntax, the username and the password need to be inserted in the command.

Syntax (Ask the Password Before Execution):

$ wget --user=<username> --ask-password <URL>

In this syntax, the username is provided only, while the password will be asked at the time of execution.

Let’s do it practically.

Example 1: Ask For Password While Executing

In the command provided below, the username “–user = username” and the password, you can use “–ask-password”, which will hide the password. Check the below command where we have provided the username and password to the HTTP link:

$ wget --user=Henry --ask-password https://download.teamviewer.com/download/linux/teamviewer_amd64.deb

The password is hidden and will not be visible to anyone.

Example 2: Provide the Password in Command

We can provide the password openly in the command, but this will be a security risk as this password can be seen using the “history” command:

$ wget --user=Henry --password='Your Password' https://download.teamviewer.com/download/linux/teamviewer_amd64.deb

In the above image, we have provided the username and password which is visible to all.

That’s how the username and the password can be provided.

Conclusion

To provide the username and password to the wget command, the user can use the “–user” for the “–password” options for username and password, respectively. Moreover, the “–ask-password” option will ask for the password at the time of execution. This post has briefly demonstrated the process of providing a username and password to wget.