curl 命令行 POST 密码
curl command line POST password
我有以下运行良好的 curl 命令:
curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form 'password=yyy' 'http://example.com'
它登录站点 http://example.com 发布一个带有变量名称用户名和密码的表单。
问题是:我不想明文传递密码。
我还尝试将密码保存在工作目录中名为 passwd 的文件中 (chmod 600 passwd) 并使用以下 curl 命令(这就是我使用 --form 而不是 --data 的原因,这将使用明文密码工作正常),但是,它不起作用:
curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form 'password=<passwd' 'http://example.com'
关于如何解决这个问题有什么建议吗?
此致,
斯特凡诺
在环境变量中设置密码,例如export PASSWD=secret
并在 --form "password=${PASSWD}"
.
中使用它
Hans Z. 回答使用环境变量在我看来是正确的。尽管我可能只是在 bash 中添加了这一点,但您可以使用 read
命令,该命令会提示输入密码并且不会使其在历史记录中可见。
所以用法应该是这样的
$ read -s PASSWD # -s is there so the characters you type don't show up
$ curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form "password=${PASSWD}" 'http://example.com'
更新:
在评论中找到的另一种解决方案是使用 curl
的 --data-urlencode name@filename
参数。
引用联机帮助页:
name@filename
This will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST.
最后的命令看起来像
$ curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--data 'username=xxx' --data-urlencode "password@passwd" 'http://example.com'
在命令行中传递机密是不安全的,因为它们在进程列表中可用。
您应该使用 --data-urlencode name@filename
方法
This will make curl load data from the given file
(including any newlines), URL-encode that data and
pass it on in the POST.
或 -K, --config <file>
Specify a text file to read curl arguments from. The
command line arguments found in the text file will be used
as if they were provided on the command line.
另见 this anwser
我有以下运行良好的 curl 命令:
curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form 'password=yyy' 'http://example.com'
它登录站点 http://example.com 发布一个带有变量名称用户名和密码的表单。
问题是:我不想明文传递密码。
我还尝试将密码保存在工作目录中名为 passwd 的文件中 (chmod 600 passwd) 并使用以下 curl 命令(这就是我使用 --form 而不是 --data 的原因,这将使用明文密码工作正常),但是,它不起作用:
curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form 'password=<passwd' 'http://example.com'
关于如何解决这个问题有什么建议吗?
此致, 斯特凡诺
在环境变量中设置密码,例如export PASSWD=secret
并在 --form "password=${PASSWD}"
.
Hans Z. 回答使用环境变量在我看来是正确的。尽管我可能只是在 bash 中添加了这一点,但您可以使用 read
命令,该命令会提示输入密码并且不会使其在历史记录中可见。
所以用法应该是这样的
$ read -s PASSWD # -s is there so the characters you type don't show up
$ curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--form 'username=xxx' --form "password=${PASSWD}" 'http://example.com'
更新:
在评论中找到的另一种解决方案是使用 curl
的 --data-urlencode name@filename
参数。
引用联机帮助页:
name@filename This will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST.
最后的命令看起来像
$ curl --silent --location -cookie "$COOKIE" --cookie-jar "$COOKIE" \
--data 'username=xxx' --data-urlencode "password@passwd" 'http://example.com'
在命令行中传递机密是不安全的,因为它们在进程列表中可用。
您应该使用 --data-urlencode name@filename
方法
This will make curl load data from the given file
(including any newlines), URL-encode that data and
pass it on in the POST.
或 -K, --config <file>
Specify a text file to read curl arguments from. The
command line arguments found in the text file will be used
as if they were provided on the command line.
另见 this anwser