CURL works only as root
Solution 1
I checked the curl google.com
strace 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.
Related videos on Youtube
khadafi
I'm a ruby on rails developer and I use Ubuntu as my favorite operating system and sometimes OSX.
Updated on September 17, 2022Comments
-
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 over 13 yearsWhat about wget? Just curious.
-
khadafi over 13 yearswget, that worked!
-
Gilles 'SO- stop being evil' over 13 yearsIs
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 differentPATH
settings (what doestype curl
say)? -
khadafi over 13 yearsI checked it and for both user it's curl is /usr/bin/curl.
-
Gilles 'SO- stop being evil' over 13 yearsDo you have SELinux or AppArmor active?
-
-
khadafi over 13 yearsthe environment variable isn't set for both user and a .curlrc file also doesn't seems to be the solution.
-
khadafi over 13 yearsThe re-installation didn't helped. But here is the output of strace curl google.com pastebin.com/bmFeK6Xn
-
Gilles 'SO- stop being evil' over 13 yearsAlso the contents of
/etc/host.conf
and/etc/gai.conf
(at least if there are non-comment lines). -
whitequark over 13 years@Gilles: thanks, added them. just never seen these files anywhere, so they missed my eye...
-
Gilles 'SO- stop being evil' over 13 yearsI'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 agetaddrinfo
call.