2

This is odd, I try to download a html file using wget

wget --user=xxx --password=yyy http://192.168.1.1/

When I execute it as myself, it works, when I execute it as root it fails with message:

Connecting to 192.168.1.1:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized

Where to look for the difference? What is the cause of this? It looks like external party can tell what login I am using :-).

The url is my router address, I need to fetch its config on regular basis.

Update 1: for the record:

sudo -u regular_user wget --user=xxx --password=yyy http://192.168.1.1/

from root account works.

Update 2: I don't have $HOME/.wgetrc for any of the users, WGETRC is not set for any of the users. Password and login does not contain anything else than 7-bit ASCII.

Update 3: no wget.rc either.

Update 4: output from wget (to Álex Sáez answer):

Connecting to 192.168.1.1:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 401 Unauthorized
  Server: micro_httpd
  Cache-Control: no-cache
  Date: Sat, 01 Jan 2000 13:32:51 GMT
  WWW-Authenticate: Basic realm="U.S. Robotics ADSL Gateway"
  Content-Type: text/html
  Connection: close
Connecting to 192.168.1.1:80... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 Ok
  Server: micro_httpd
  Cache-Control: no-cache
  Date: Sat, 01 Jan 2000 13:32:51 GMT
  Content-Type: text/html
  Connection: close
Length: unspecified [text/html]
Saving to: ‘index.html’
4
  • 1
    Maybe there is a wget.rc in the root home folder that is messing up with the connection. And are the locales of both users (root and non-privilege user) the same? Because if not, maybe the password has non-ASCII characters and you are sending weird data to the web page. Apr 15 '15 at 8:43
  • Are you using the same --user and --pasword when running as root? It's not clear from your question.
    – terdon
    Apr 15 '15 at 8:43
  • @terdon, yes, I am just switching the user in console. Apr 15 '15 at 8:45
  • @ÁlexSáez, thank you for the hint, it has to be something else though. Apr 15 '15 at 9:12
1

Try with --ask-password and the --server-response parameters. Like:

wget --server-response --user username --ask-password http://192.168.1.1

And, I know it isn´t something related with the root, but try quoting the password. Just because maybe you have something like hello#123. You can type it with backslash or "hello#123".

3
  • Thank you! This is weird, when I add this "ask-password" param I get the output as I quoted now in update section -- 401+OK. When I pass password in command line I get 401 twice, and no OK response. Yes, I quote the password, it is literally same command for user and root. Ha! Solved, I tried backslashing every special character and I removed quotes instead -- it worked for root, finally. I have to idea why quotes were OK for regular user though. Apr 15 '15 at 15:39
  • Maybe the shell is different or the locales. I dunno, but let me know if you find it, 'cause I have no clue Apr 15 '15 at 16:38
  • Locales are different indeed, but as I wrote, password is 7-bit ASCII. User has "en_US.UTF-8" while root has "POSIX". Apr 15 '15 at 16:58
0

Without credentials, it works. It doesn't matter if you are super user or normal user. But as you are entering the credentials for root, then most probably the password you entered is wrong or you are simply unauthorized to access that page

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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