passing password to curl on command line passing password to curl on command line curl curl

passing password to curl on command line


You can use:

curl -u abcuser:trialrun https://xyz.abc.comp

In your script:

curl -u ${user}:${pass} ${url}

To read from stdin:

curl  https://xyz.abc.com -K- <<< "-u user:password"

When using -K, --config specify - to make curl read the file from stdin

That should work for HTTP Basic Auth, from the curl man:

-u, --user <user:password> Specify the user name and password to use for server authentication. 


To expand on @nbari's answer, if you have a tool "get-password" that can produce a password on stdout, you can safely use this invocation:

user="abcuser"url="https://xyz.abc.com"get-password $user | sed -e "s/^/-u $user:/" | curl -K- $url

The password will be written to a pipe. We use sed to massage the password into the expected format. The password will therefore never be visible in ps or in the history.