When accessing certain websites or servers using Wget, authentication might be necessary. Websites or servers that are password protected, for instance, will require a username and password for access. This is common when downloading files from private repositories, FTP servers, or HTTP sites with basic authentication.
Wget, an open-source utility for non-interactive file downloading from the web, provides options to specify the required credentials. When using Wget in scripts or for scheduled tasks, it's particularly useful to know how to provide these credentials without being prompted.
However, be cautious about where and how you store these credentials, especially when scripting, as they can be accessed by unauthorized users if not properly protected.
$ wget --user=username --password=yourpassword https://example.com/protected-resource.zip
$ wget --user=myusername --ask-password https://www.example.com/protected/resource.txt
When using –ask-password, Wget will prompt you for the password, ensuring it's not saved in command history.
$ wget --user=username --password=yourpassword ftp://ftp.example.com/private-data.tar.gz
echo "user=username password=yourpassword" > ~/.wgetrc
Make sure to set the correct permissions on the .wgetrc file to prevent unauthorized access. Use the command:
$ chmod 600 ~/.wgetrc
$ wget https://example.com/protected-resource.zip
$ read -sp "Enter Password: " PASSWORD $ wget --user=username --password=$PASSWORD https://example.com/protected-resource.zip
This way, the password is only stored temporarily in the variable and won't appear in your command history.
Always remember to be cautious with your credentials. It's essential to avoid exposing them to other users or inadvertently committing them to version control if used within scripts.
Comment anonymously. Login not required.