Curl Proxy Username Password

C

How to use curl command with proxy username/password on ...

How to use curl command with proxy username/password on …

My sysadmin provided me the following proxy details:
IP: 202. 54. 1. 1
Port: 3128
Username: foo
Password: bar
The settings worked perfectly with Google Chrome and Firefox browser. How do I use it with the curl command? How do I tell the curl command to use my proxy settings from Google Chrome browser?
Many Linux and Unix command line tools such as curl command, wget command, lynx command, and others; use the environment variable called _proxy, _proxy, ftp_proxy to find the proxy details. It allows you to connect text based session and applications via the proxy server with or without a userame/password. This page shows how to perform HTTP/HTTPS requests with cURL cli using PROXY server.
Unix and Linux curl command with proxy syntax
The syntax is:
## Set the proxy address of your uni/company/vpn network ##
export _proxy=your-ip-address:port/
## _proxy with username and password
export _proxy=user:[email protected]:port/
## HTTPS version ##
Another option is to pass the -x option to the curl command. To use the specified proxy:
curl -x <[protocol][user:[email protected]]proxyhost[:port]> url
–proxy <[protocol][user:[email protected]]proxyhost[:port]> url
–proxy user:[email protected]:Port url
-x user:[email protected]:Port url
Linux use curl command with proxy
First set the _proxy:
## proxy server, 202. 1, port: 3128, user: foo, password: bar ##
export _proxy=foo:[email protected] 1:3128/
export _proxy=$_proxy
## Use the curl command ##
curl -I curl -v -I
Sample outputs:
* Rebuilt URL to: * Trying 202. 1…
* Connected to 1202. 1 (202. 1) port 3128 (#0)
* Proxy auth using Basic with user ‘foo’
> HEAD HTTP/1. 1
> Host: > Proxy-Authorization: Basic x9VuUml2xm0vdg93MtIz
> User-Agent: curl/7. 43. 0
> Accept: */*
> Proxy-Connection: Keep-Alive
>
< HTTP/1. 1 200 OK HTTP/1. 1 200 OK < Server: nginx Server: nginx < Date: Sun, 17 Jan 2016 11:49:21 GMT Date: Sun, 17 Jan 2016 11:49:21 GMT < Content-Type: text/html; charset=UTF-8 Content-Type: text/html; charset=UTF-8 < Vary: Accept-Encoding Vary: Accept-Encoding < X-Whom: Dyno-l1-com-cyber X-Whom: Dyno-l1-com-cyber < Vary: Cookie Vary: Cookie < Link: <>; rel=”
Link: <>; rel=”
< X-Frame-Options: SAMEORIGIN X-Frame-Options: SAMEORIGIN < X-Content-Type-Options: nosniff X-Content-Type-Options: nosniff < X-XSS-Protection: 1; mode=block X-XSS-Protection: 1; mode=block < X-Cache: MISS from server1 X-Cache: MISS from server1 < X-Cache-Lookup: MISS from server1:3128 X-Cache-Lookup: MISS from server1:3128 < Connection: keep-alive Connection: keep-alive < * Connection #0 to host 10. 12. 249. 194 left intact In this example, I’m downloading a pdf file: $ export _proxy="vivek:[email protected] 194:3128/" $ curl -v -O OR use the -x option: curl -x 'vivek:[email protected] 194:3128' -v -O Sample outputs: Fig. 01: curl in action (click to enlarge) How to use the specified proxy server with curl on Unix $ curl -x prox_server_vpn:3128/ -I How to use socks protocol? The syntax is same: curl -x socks5[user:[email protected]]proxyhost[:port]/ url curl --socks5 192. 168. 254:3099 How do I configure and setup curl to permanently use a proxy connection? Update/edit your ~/ file using a text editor such as vim: $ vi ~/ Append the following: Patreon supporters only guides proxy = proxy-user = "foo:bar" Save and close the file. Another option is create a bash shell alias in your ~/ file: ## alias for curl command ## set proxy-server and port, the syntax is ## alias curl="curl -x {your_proxy_host}:{proxy_port}" alias curl="curl -x " Remember, the proxy string can be specified with a protocol prefix to specify alternative proxy protocols. Use socks4, socks4a, socks5 or socks5h to request the specific SOCKS version to be used. No protocol specified, and all others will be treated as HTTP proxies. If the port number is not specified in the proxy string, it is assumed to be 1080. The -x option overrides existing environment variables that set the proxy to use. If there’s an environment variable setting a proxy, you can set proxy to “” to override it. See curl command man page here for more info. ADVERTISEMENT CategoryList of Unix and Linux commandsDocumentationhelp • mandb • man • pinfoDisk space analyzersdf • duf • ncdu • pydfFile Managementcat • cp • less • mkdir • more • treeFirewallAlpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16. 04 • Ubuntu 18. 04 • Ubuntu 20. 04Linux Desktop AppsSkype • Spotify • VLC 3Modern utilitiesbat • exaNetwork UtilitiesNetHogs • dig • host • ip • nmapOpenVPNCentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18. 04Package Managerapk • aptProcesses Managementbg • chroot • cron • disown • fg • glances • gtop • jobs • killall • kill • pidof • pstree • pwdx • time • vtopSearchingag • grep • whereis • whichShell builtinscompgen • echo • printfText processingcut • revUser Informationgroups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • wWireGuard VPNAlpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20. 04 curl ootw: -U for proxy credentials - Daniel Stenberg

curl ootw: -U for proxy credentials – Daniel Stenberg

(older options of the week)
-U, –proxy-user
The short version of this option uses the uppercase letter ‘U’. It is important since the lower case letter ‘u’ is used for another option. The longer form of the option is spelled –proxy-user.
This command option existed already in the first ever curl release!
The man page‘s first paragraph describes this option as:
Specify the user name and password to use for proxy authentication.
Proxy
This option is for using a proxy. So let’s first briefly look at what a proxy is.
A proxy is a “middle man” in the communication between a client (curl) and a server (the one that holds the contents you want to download or will receive the content you want to upload).
The client communicates via this proxy to reach the server. When a proxy is used, the server communicates only with the proxy and the client also only communicates with the proxy:
curl <===> proxy <===> server
There exists several different types of proxies and a proxy can require authentication for it to allow it to be used.
Proxy authentication
Sometimes the proxy you want or need to use requires authentication, meaning that you need to provide your credentials to the proxy in order to be allowed to use it. The -U option is used to set the name and password used when authenticating with the proxy (separated by a colon).
You need to know this name and password, curl can’t figure them out – unless you’re on Windows and your curl is built with SSPI support as then it can magically use the current user’s credentials if you provide blank credentials in the option: -U:.
Security
Providing passwords in command lines is a bit icky. If you write it in a script, someone else might see the script and figure them out.
If the proxy communication is done in clear text (for example over HTTP) some authentication methods (for example Basic) will transmit the credentials in clear text across the network to the proxy, possibly readable by others.
Command line options may also appear in process listing so other users on the system can see them there – although curl will attempt to blank them out from ps outputs if the system supports it (Linux does).
Needs other options too
A typical command line that use -U also sets at least which proxy to use, with the -x option with a URL that specifies which type of proxy, the proxy host name and which port number the proxy runs on.
If the proxy is a HTTP or HTTPS type, you might also need to specify which type of authentication you want to use. For example with –proxy-anyauth to let curl figure it out by itself.
If you know what HTTP auth method the proxy uses, you can also explicitly enable that directly on the command line with the correct option. Like for example –proxy-basic or –proxy-digest.
SOCKS proxies
curl also supports SOCKS proxies, which is a different type than HTTP or HTTPS proxies. When you use a SOCKS proxy, you need to tell curl that, either with the correct prefix in the -x argument or by with one of the –socks* options.
Example command line
curl -x -U user:password
See Also
The corresponding option for sending credentials to a server instead of proxy uses the lowercase version: -u / –user.
tech, open source and networking
curl through authenticated proxy and authenticated http resource

curl through authenticated proxy and authenticated http resource

I want to do a post (twitter in this case) with a oneliner.
If I don’t have proxy
curl -u user:pass -d status=”message”
works perfectly.
But when I am behind a authenticated proxy it doesn’t.
I had tryied:
curl -X proxy:port -U proxyUser:proxyPass -u user:pass -d status=”message”
That it jump me with an
proxy do not support basic auth
So do you know what I am doing wrong?
thanks in advance.
asked Nov 6 ’10 at 0:08
Cababunga’s answer is correct, but they’re missing another option: –proxy-ntlm. Some proxies won’t authorize correctly with –proxy-anyauth, so ideally you’ll want to specify the authentication method that your proxy uses. If you run curl -v -U user:pass -x proxy:port –url, you should get something along the lines of the following:
About to connect() to proxy [your proxy] port [your port] (#0)
Trying [IP]…
connected
Connected to [your proxy] ([IP]) port [your port] (#0)
Establish HTTP proxy tunnel to Proxy auth using Basic with user ‘[user]’
CONNECT HTTP/1. 1
Host: Proxy-Authorization: Basic [gibberish]
User-Agent: curl/[ver] ([OS]) libcurl/[ver] OpenSSL/[ver] zlib/[ver]
Proxy-Connection: Keep-Alive
HTTP/1. 1 407 Proxy Authentication Required
Proxy-Authenticate: NEGOTIATE
Proxy-Authenticate: NTLM
Add a flag for whatever you see in the Proxy-Authenticate parameter and you should be good to go. In this example, you would add the –proxy-ntlm flag.
spottedmahn12. 1k8 gold badges82 silver badges146 bronze badges
answered Feb 28 ’13 at 17:15
MicahMicah1811 silver badge3 bronze badges
You may be able to put the username/password in the URL for the authenticated resource to avoid having extra command line complications.
also, the –proxy shortcut is a lowercase x, as cababunga pointed out.
curl -x proxyaddr:port -U proxyUser:proxyPass -u user:pass -d status=”message”
answered Nov 6 ’10 at 11:32
tweak2tweak26035 silver badges15 bronze badges
Try to add –proxy-digest or –proxy-anyauth.
And I think to connect to proxy you should use lower case -x (not -X).
answered Nov 6 ’10 at 0:33
cababungacababunga3, 00313 silver badges23 bronze badges
You may want to try using SOCKS v5 instead of v4:
$ curl –proxy socks5proxyUser:[email protected]:port…
answered Mar 28 ’17 at 15:01
WernightWernight32. 9k23 gold badges111 silver badges131 bronze badges
I managed to perform this with the help of the Micah’s answer here:
this is the command I got at the end to access a BitBucket repo:
curl -u userBitbucket:PwdBitBucket -U userProxy:pwdProxy -x address_proxy:port:proxy –proxy-ntlm host:port/projects/project/repos/repo/browse/file
answered Dec 15 ’16 at 10:13
Ualter Jr. 2, 0881 gold badge22 silver badges24 bronze badges
Not the answer you’re looking for? Browse other questions tagged rest curl or ask your own question.

Frequently Asked Questions about curl proxy username password

How do I find my proxy username and password?

Click on the Proxies tab and you’ll see a bunch of different protocols you can configure. For example, if you click on Web Proxy (HTTP), you’ll be able to enter the proxy server IP address, port number, username and password.Oct 2, 2017

How do I get my curl username and password?

For example, if a website has protected content curl allows you to pass authentication credentials. To do so use the following syntax: curl –user “USERNAME:PASSWORD” https://www.domain.com . “USERNAME” must be replaced with your actual username in quotes.May 5, 2019

How do I use a proxy to curl?

On Curl for example you can set the proxy using the –proxy flag:curl http://example.com –proxy 127.0.0.1:8080. Sh.proxy = 127.0.0.1:8080.http_proxy = http://127.0.0.1:8080.Apr 17, 2018

About the author

proxyreview

If you 're a SEO / IM geek like us then you'll love our updates and our website. Follow us for the latest news in the world of web automation tools & proxy servers!

By proxyreview

Recent Posts

Useful Tools