One of the most common advices you’ll see online is to use a strong password. Security experts often suggest to includes a mix of different numbers, symbols or special characters, capital letters, and lower-case letters to make the password harder to crack for the hackers. It is pretty obvious that almost everyone of us using a password having special characters. In this post, I will show how to specify username and password with special characters while making curl requests from terminal.
curl is a solid and simple tool that allows transferring data from and to any server with command line using various protocols including HTTP.
curl to access the site that required http authentication, need to use -u to pass username and password with a
colon between them i.e.
curl -u username:password https://cleanprogrammer.net
Sometimes username/password contains special characters like exclamation mark, slash etc. In that case, passing them with above pattern (user/name:pass!word) won’t work.
curl -u user\name:pass!word https://cleanprogrammer.net
The above request will fail. In this case, we need to pass the username and password by escaping the special characters with
\. So the curl request should be:
curl -u user\\name:pass\!word https://cleanprogrammer.net
That’s it. By escaping the special characters with the
\ you’ll be able to specify them while making curl requests from terminal.