Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to pass the username and password from a file instead of the command line via --user and --password?

Background: I want to run wget via cron and don't want the username/password show up in process view

share|improve this question
up vote 10 down vote accepted

Use a .wgetrc file (GNU manual) in which you can set username and passwords for either or both ftp and http.

To use the same credentials for both specify


or individually

share|improve this answer
The GNU wget manual also suggests using the -i option and feeding the username and password in from standard input. – Richard May 8 '11 at 15:08

I'm surprised nobody mentioned the .netrc file. First create the file if it doesn't exists and set safe permissions:

touch ~/.netrc
chmod 600 ~/.netrc

Then you can add the hostname, username and password all on one line:

echo 'machine login casper password CasperPassword' >> ~/.netrc

Then when you do wget and the server responds with 401 Authorization Required, wget will retry with the username and password from the ~/.netrc file.

When using this from cron make sure you have the right HOME directory. Often cron sets HOME=/ (in that case you would have to create the file as /.netrc, but it's better to set a proper HOME at the beginning of your script, like export HOME=/root).

You can specify multiple hosts in ~/.netrc, one per line. More info in man netrc.

share|improve this answer

In many regards curl can be a better choice. Wget became a bit stale over time.

curl's -n switch can be used for this task:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.