CURL works only as root

5,812

Solution 1

I checked the curl google.comstrace log and the key line is surely 409:

connect(3, {sa_family=AF_INET, sin_port=htons(9999), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)

If I (for the testing) launch curl http://localhost:1357, I get in the strace:

connect(3, {sa_family=AF_INET, sin_port=htons(1357), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EINPROGRESS (Operation now in progress)

So, by some weird reason instead of google.com curl tries to connect to localhost:9999.

Can you post:

  • /etc/hosts
  • /etc/nsswitch.conf
  • ~/.bashrc
  • /etc/host.conf
  • /etc/gai.conf
  • output of ldd /usr/bin/curl
  • output of env

Solution 2

Maybe one user is using a proxy and the other one isn't. See if either your user or root has the http_proxy or HTTP_PROXY environment variable defined.

Also see if root has a .curlrc file that contains an option that makes it work, or if your user has a .curlrc that makes it not work.

Solution 3

I am thinking that maybe some library that curl needs is now only accessible by root for whatever reason. A couple of things you could try:

sudo apt-get purge curl libcurl3
sudo apt-get install curl

then, if that doesn't fix it:

strace curl http://site.com/file.txt &> curl.log

and post the output on pastebin.com or something for us.

Share:
5,812

Related videos on Youtube

khadafi
Author by

khadafi

I'm a ruby on rails developer and I use Ubuntu as my favorite operating system and sometimes OSX.

Updated on September 17, 2022

Comments

  • khadafi
    khadafi over 1 year

    I'm on an Ubuntu 10.04 installation and somehow curl stopped working with my user. I always receive: curl: (7) couldn't connect to host. It only works as root. Can anyone help me?

    • nelsonjchen
      nelsonjchen over 13 years
      What about wget? Just curious.
    • khadafi
      khadafi over 13 years
      wget, that worked!
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' over 13 years
      Is curl an alias of shell function for one of the user, or do you have more than one version installed with the users reaching different versions because of different PATH settings (what does type curl say)?
    • khadafi
      khadafi over 13 years
      I checked it and for both user it's curl is /usr/bin/curl.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' over 13 years
      Do you have SELinux or AppArmor active?
  • khadafi
    khadafi over 13 years
    the environment variable isn't set for both user and a .curlrc file also doesn't seems to be the solution.
  • khadafi
    khadafi over 13 years
    The re-installation didn't helped. But here is the output of strace curl google.com pastebin.com/bmFeK6Xn
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 13 years
    Also the contents of /etc/host.conf and /etc/gai.conf (at least if there are non-comment lines).
  • whitequark
    whitequark over 13 years
    @Gilles: thanks, added them. just never seen these files anywhere, so they missed my eye...
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 13 years
    I'd never seen them either, but the # Configuration for getaddrinfo at the top of /etc/gai.conf caught my eye. And line 409 is a replay of 386, which presumably follows a getaddrinfo call.